#include<iostream>
using namespace std;
class B
{
public:
B()
{
cout << "default constructor" << " ";
}
~B()
{
cout << "destructed" << " ";
}
B(int i) : data(i)
{
cout << "constructed by parameter" << data << " ";
}
private: int data;
};
B Play(B b)
{
return b;
}
int main(int argc, char *argv[])
{
B temp = Play(5);
system("pause");
return 0;
}
此代码中的有参构造函数会覆盖无参构造函数。