可以!因为C++里有拷贝构造函数,通过拷贝构造函数实现对象相互赋值。
如:
#include <iostream.h>
class student
{
public:
student(){}
student(int n){name = n;}
student(student & stu){} //拷贝构造函数,没写时系统自动分配
void display(){cout<<name<<endl;}
private:
int name;
};
void main()
{
student s1(10),s3;
s3 = s1;
s3.display();
}