尝试将值加载到List对象中,我得到“对象引用未设置为对象的实例”错误。
(编辑问题以简化它)
MyVec.h列表(仅限要点):
ref class MyVec { public: List<double>^ MyVector; MyVec(void); };MyVec.cpp列表(仅限要点):
#include "MyVec.h" MyVec::MyVec(void) { }Form.h列表(仅限要点):
MyVec^ TestVec = gcnew MyVec(); double MyDouble = 1.002; TestVec->MyVector->Add(MyDouble); textBox1->Text = TestVec->MyVector[0].ToString() + "\r\n";我在尝试将MyDouble分配给TestVec时遇到错误:TestVec-> MyVector-> Add(MyDouble)
在Autos窗口中,它表示(除其他外)TestVec-> MyVector未定义的值
怎么了?
Trying to load values into a List object, I get the "Object reference not set to an instance of an object" error.
(edited question to simplify it)
MyVec.h listing (essentials only):
ref class MyVec { public: List<double>^ MyVector; MyVec(void); };MyVec.cpp listing (essentials only):
#include "MyVec.h" MyVec::MyVec(void) { }Form.h listing (essentials only):
MyVec^ TestVec = gcnew MyVec(); double MyDouble = 1.002; TestVec->MyVector->Add(MyDouble); textBox1->Text = TestVec->MyVector[0].ToString() + "\r\n";I get the error where I try to assign MyDouble to TestVec: TestVec->MyVector->Add(MyDouble)
In the Autos window it says (amongst other things) TestVec->MyVector undefined value
What's wrong?
最满意答案
这个改变应该解决问题:
MyVec::MyVec(void) { MyVector = gcnew List<double>(); }类成员MyVector是initailly null引用。 您需要在使用之前初始化它,并且MyVec构造函数是适当的位置。
This change should solve the problem:
MyVec::MyVec(void) { MyVector = gcnew List<double>(); }Class member MyVector is initailly null reference. You need to initialize it before using, and MyVec constructor is appropriate place to do it.
更多推荐
MyDouble,MyVec,TestVec,TestVec->MyVector,电脑培训,计算机培训,IT培训"/> <m
发布评论