我是一个新手,对对象创建和构造函数之间的关系有一个基本的疑问。
程序- 1
#include<iostream>
using namespace std;
class xxx{
private: int x;
public: xxx(){cout<<"constructer is called"<<endl;}
};
int main(int argc, char *argv[])
{
xxx x1; //Constructor is called
return 0;
}
输出构造函数被调用
程序- 2
#include<iostream>
using namespace std;
class xxx{
private: int x;
public: xxx(){cout<<"constructer is called"<<endl;}
};
int main(int argc, char *argv[])
{
xxx x1(); //Constructor xxx() is not called.
return 0;
}
输出-空白 任何信息都非常有帮助