65,185
社区成员




#include<iostream>
using namespace std;
class A
{
int x,y;
public:
A(int i=0,int j=0)
{
x=i;
y=j;
show();
cout<<"Constructor called.\n";
}
A(A &a);
~A()
{
show();
cout<<"Destructor called.\n";
}
void set(int i=0,int j=0){x=i;y=j;}
void show(){cout<<x<<','<<y<<',';}
};
A::A(A &a)
{
x=a.x;
y=a.y;
show();
cout<<"Copy constructor called.\n";
}
A fun(A a)
{
a.show();
cout<<endl;
a.set(3,7);
return a;
}
int main()
{
A a1,a2(6,8),a3(a2),a4;
a4= fun(a3);
a4.show();
a3.show();
cout<<endl;
return 0;
}