———————标准输入输出———————
?系统会自动生成浅拷贝,就相当于直接赋值
#include "iostream" using namespace std; class base { public: base(int a, int b) : a(a), b(b) { } int a; int b; }; int main() { base newbase1(10, 20); base newbase2 = newbase1; cout << newbase1.a << endl; cout << newbase1.b << endl; cout << newbase2.a << endl; cout << newbase2.b << endl; }
?重写拷贝构造函数(浅拷贝 图片+代码段)
#include "iostream" using namespace std; class base { public: base(int a, int b) : a(a), b(b) { } base(base &a) { cout << "重写拷贝构造" << endl; } int a; int b; }; int main() { base newbase1(10, 20); base newbase2 = newbase1; }
———————End———————