在下面的代码中,我收到此错误:对象引用未设置为对象的实例
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;”行中运行时 这是一个未定义的值!
为什么呢?怎么了?