class myBase
{
public:
void display();
myBase(int,int);
int a;
int b;
};
void myBase::display()
{
cout<<a<<b<<endl;
}
myBase::myBase(int c,int d)
{
a=c;
b=d;
}
void main()
{
myBase B(1,2),C(3,4);
B.display();
C.display();
C=B;
C.display();
myBase D(B);
D.display();
}
输出为:
12
34
12
12
看来,C++有默认的拷贝构造函数和赋值运算符=!
{
public:
void display();
myBase(int,int);
int a;
int b;
};
void myBase::display()
{
cout<<a<<b<<endl;
}
myBase::myBase(int c,int d)
{
a=c;
b=d;
}
void main()
{
myBase B(1,2),C(3,4);
B.display();
C.display();
C=B;
C.display();
myBase D(B);
D.display();
}
输出为:
12
34
12
12
看来,C++有默认的拷贝构造函数和赋值运算符=!