可能重复:
带空括号的默认构造函数
这是我处理的代码,我不明白它在构造函数 Package obj2() 上发生了什么;输出时仅显示值 4 (Package obj1(4)) 和 2 (Package obj3(2))
#include <iostream>
using namespace std;
class Package
{
private:
int value;
public:
Package()
{
cout<<"constructor #1"<<endl;
value = 7; cout << value << endl;
}
Package(int v)
{
cout<<"constructor #2"<<endl;
value = v; cout << value << endl;
}
~Package()
{
cout<<"destructor"<<endl;
cout << value << endl;
}
};
int main()
{
Package obj1(4);
Package obj2();
Package obj3(2);
}