拷贝构造函数是用一个对象初始化另外一个对象时候使用;
class student
{
public:
student()
{
strcpy(name,"xxj");
age =10;
};
student(const student &stu)//拷贝构造函数
{
this.age = stu.age;
stcpy(this.name,stu.name);
};
char *name[64];
int age;
}
int main()
{
student stu;
student stu1(stu);//此时调用拷贝构造
}
赋值构造函数是有两个对象,用其中要给对象给另外一个对象赋值时候使用:
class student
{
public:
student()
{
strcpy(name,"xxj");
age =10;
};
student(char *name[64],int age)
{
strcpy(this.name,name);
age =10;
};
student(const student &stu)//拷贝构造函数
{
this.age = stu.age;
stcpy(this.name,stu.name);
};
char *name[64];
int age;
}
int main()
{
student stu;
student stu1("xxj",18);//此时调用拷贝构造
stu = stu1;//此时调用赋值构造函数
}