以下は、私の問題を再現する最小のプログラムです。
#include <iostream>
using namespace std;
class Test
{
public:
Test()
{
_a = 0;
}
Test(int t)
{
Test();
_b = t;
}
void Display()
{
cout << _a << ' ' << _b << endl;
}
private:
int _a;
int _b;
};
int main()
{
Test test(10);
test.Display(); // 70 10
return 0;
}
これを行う_a
と、ガベージで初期化されます。なぜこれが起こるのですか?コンストラクターが別のコンストラクター内から呼び出されたときに問題はありますか?