0

以下のコードでは、このエラーが発生します: オブジェクト参照がオブジェクトのインスタンスに設定されていません

public ref class UtilityFunction
{
    UtilityFunction(void)
    {
        temp = 2;
    }

    public:
    int temp;

    public: void runTest()
    {
        int tmp = this -> temp;   //this line gets error
    }
};

別のクラス内で呼び出されます。

public ref class Startup : public System::Windows::Forms::Form
{

private: void foo()
    {
        UtilityFunction^ utilityfunc;
        utilityfunc->runTest();
    }
};

「int tmp = this -> temp;」の行で実行する場合 これは未定義の値です。

どうしてこんなことに?どうしたの?

4

1 に答える 1