⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 copy.cc

📁 资深C++讲师授课代码
💻 CC
字号:
#include <iostream>
#include <cstring>
using namespace std;

class String{
	char* str;
public:
	String(const char* s=""){
		str = new char[strlen(s)+1];
		strcpy(str, s);
		cout << "new " << (void*)str << ':' << str << endl;
	}
	~String(){
		cout << "delete " << (void*)str << ':' << str << endl;
		delete[] str; str=NULL;
	}
	String& operator=(const String& s2){
		if(this==&s2) return *this;
		cout << "delete " << (void*)str << ':' << str << endl;
		delete[] str;
		str = new char[strlen(s2.str)+1];
		strcpy(str, s2.str);
		cout << "new " << (void*)str << ':' << str << endl;
		return *this;
	}
	String(const String& s){
		str = new char[strlen(s.str)+1];
		strcpy(str, s.str);
		cout << "new " << (void*)str << ':' << str << endl;
	}
};
int main()
{
	String s1("good"), s2("morning");
	String s3(s1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -