我是 C++ 的新手,目前正在处理我的任务,并在尝试使用 for 循环将迭代器指针分配给数组时遇到运行时错误“访问冲突读取位置”。
Flist = data.getFList();
for(Fit = Flist.begin(); Fit != Flist.end(); Fit++)
{
++counter;
cout << "(" << counter << ") Destination: " << Fit->getDest() << " [Class: " ><< Fit->getClass() << "]" << endl;
_getch();
fArr[counter] = *Fit;
}
构造函数
Staff::Staff()
{
counter = 0;
fArr = new Flight[counter];
};
标题
Flight *fArr;
int counter;
任何帮助都会很棒~
最佳答案
当您在构造函数中分配内存时,您正在创建一个 0
的数组。大小,这真的没有意义。
相反,只需使用航类 vector :std::vector<Flight> fArr
,然后推回给它:
fArr.push_back(*Fit);
关于c++ - 访问冲突读取位置 0xcccccd84,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18918854/