質問があります:C++でClassName instance()
のクラスのインスタンスを作成するときに使用されるコンストラクタは何ですか?クラスのインスタンスを作成する
例:
#include <iostream>
using namespace std;
class Test
{
private:
Test()
{
cout << "AAA" << endl;
}
public:
Test(string str)
{
cout << "String = " << str << endl;
}
};
int main()
{
Test instance_1(); // instance_1 is created... using which constructor ?
Test instance_2("hello !"); // Ok
return 0;
}
ありがとう!
これは私が言っていたことですが、あなたは私にそれを打ち負かしました。これはC++の最も厄介な構文解析(http://en.wikipedia.org/wiki/Most_vexing_parse)です。 –
最も厄介な構文解析は非常に適切な名前です!このタグhttp://stackoverflow.com/questions/tagged/most-vexing-parseの下にある質問は素晴らしい証拠です。 – tomasz