定义和赋值的区别 构造函数和拷贝构造函数 type a;type b=a; //调用拷贝构造函数type d(a); //调用拷贝构造函数type c;c=a ; //赋值语句,调用默认构造函数,重载=,改变行为. class ClsA{public: char* Name; bool Sex; ClsA(char* v,bool sex) { cout<<"构造函数"<<endl; if(v) { Name = new char[strlen(v)+1]; strcpy(Name,v); } else { Name = NULL; } Sex = sex; } ~ClsA() { cout<<"析构函数"<<endl; delete[] Name; } ClsA(const ClsA & A) { cout<<"拷贝构造函数"<<endl; if(A.Name) { Name = new char[strlen(A.Name)+1]; strcpy(Name,A.Name); } else { cout<<"A.Name is NULL"; } Sex = A.Sex; } // ClsA& operator = (const ClsA& R) // { // cout<<"operator : ="<<endl; // delete[] Name; // if(R.Name) // { // Name = new char[strlen(R.Name)+1]; // strcpy(Name,R.Name); // } // else // { // cout<<"R.Name is NULL"; // } // Sex = R.Sex;// // return *this;// // }};