我需要将字符串拆分成一个数组。当我试图向数组中添加新对象时,我得到了object reference not set to an instance of an object:
array<d3^> ^pr_d3; //d3 - class
parts = sr->ReadLine()->Split(
(array<String^>^)nullptr,
StringSplitOptions::RemoveEmptyEntries); //array<String ^> ^parts;
pr_d3[0] = gcnew d3(
parts[0], parts[1],
parts[2],
Convert::ToInt16(parts[3]), Convert::ToInt16(parts[4])); //error关于Ideon的代码
发布于 2016-02-17 15:13:16
您没有初始化数组pr_d3。
删除正确的代码后,您现在拥有以下内容:
array<d3^> ^pr_d3;
pr_d3[0] = gcnew d3(...);错误正在试图访问[0] of pr_d3,但是pr_d3仍然是空的。
您需要使用pr_d3初始化gcnew array<d3^>(<some array size>),或者如果您不确定需要的大小,则使用List<d3^>代替。
https://stackoverflow.com/questions/35453727
复制相似问题