64,701
社区成员
发帖
与我相关
我的任务
分享
class A
{
public:
explicit A(int a):mem(a) {cout<<"a constructor"<<mem<<endl;}
A():mem(0){cout<<__func__<<endl;}
A(const A &t) {cout<<"copy"<<endl;}
A operator=(const A &t) {cout<<__func__<<endl;}
~A() {}
A add(const A &one, const A & two);
int mem;
};
A A::add(const A &one, const A & two)
{
cout<<__func__<<endl;
A tmp;
tmp.mem=one.mem+two.mem;
return tmp;
}
int main(int argc, char const *argv[])
{
A res2=res2.add(A(10), A(20));
cout<<res2.mem<<endl;
return 0;
}