代码
#include <iostream> using namespace std; class AA { public: AA(int i,int j) { A=i; B=j; cout<<"Constructor\n"; } AA(AA &obj) { A=obj.A+1; B=obj.B+2; cout<<"Copy_Constructor\n"; } ~AA() { cout<<"Destructor\n"; } void print() { cout<<"A="<<A<<",B="<<B<<endl; } private: int A,B; }; int main() { AA a1(2,3); AA a2(a1); a2.print(); AA *pa=new AA(5,6); pa->print(); delete pa; return 0; }
运行结果:
学习心得:
好好学习 天天向上
原文地址:http://blog.csdn.net/ljd939952281/article/details/45054075