Tag Archives: 深拷贝

自定义字符串类String,实现运算符重载,内存管理

1、String.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once
#include <iostream>
using namespace std;
 
class String {
	friend ostream &operator << (ostream &, String &);
private:
	char *m_name = NULL;
	char *setM_name(const char *cstring);
	char *strAppend(const char *, const char *);
public:
	String(const char *cstring = "");
	String(const String &);
	~String();
	bool operator == (String &string);
	String &operator = (String &string);
	String &operator = (const char *cstring);
	String operator + (const char *cstring);
	String operator + (const String &string);
	String &operator += (const char *cstring);
	String &operator += (const String &string);
	char operator[](int index);
	bool operator<(const String &string);
};
 
ostream &operator << (ostream &cout, String &string);
</iostream>

2、String.cpp

[……]

继续阅读