次の構造体とクラスを取ります。
struct TestStruct
{
};
class TestClass
{
public:
TestStruct* testStruct;
};
で次の操作を行いますmain
。
TestClass testClass;
if (testClass.testStruct == NULL)
cout << "It is NULL." << endl;
else
cout << "It is NOT NULL.";
出力は次のようになりますIt is NOT NULL.
。
ただし、代わりにこれを行うと:
TestClass testClass;
if (testClass.testStruct == NULL)
cout << "It is NULL." << endl;
else
cout << "It is NOT NULL." << endl << testClass.testStruct;
出力は次のようになりますIt is NULL.
。
興味深いことに、これを行うと(基本的に上記と同じ):
TestClass testClass;
if (testClass.testStruct == NULL)
{
cout << "It is NULL." << endl;
}
else
{
cout << "It is NOT NULL." << endl;
cout << testClass.testStruct;
}
出力は次のようになります。
It is NOT NULL.
0x7fffee043580.
何が起こっている?