#include <iostream>
using namespace std;
class B
{
public:
B()
{
cout<<"default constructor"<<endl;
}
~B()
{
cout<<"destructed"<<endl;
}
B(int i):data(i)
{
cout<<"constructed: " << data <<endl;
}
private:
int data;
};
B Play(B b)
{
return b ;
}
int main()
{
B temp = Play(5);
return 0;
}
运行结果:
学习心得;
在主函数上面定义了一个B类的对象Play,且返回值为b,然后主函数中定义了一个类的新对象,并将Play的值复制给了temp.