私は初心者で、オブジェクトの作成とコンストラクターの関係について基本的な疑問を持っています。
プログラム-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;
}
出力 - 空白の 情報は非常に役立ちます