我正在使用一个名为tArray的对象,它是一个对象数组,并且确实可以正常工作以执行所有其他任务。我需要使用对象数组中的buyerName形成一个字符串数组,以填充它的新数组,然后将其返回。然而,我不断收到我的标题所述的错误,有谁知道为什么?到目前为止,我只在这个方法上苦苦挣扎。感谢C++ - 访问冲突读取位置0xcccccccc
的代码这第一个块被用于调用该方法在我的分析器类
std::string *topBuyers = analyser.topFiveBuyers();
for(int idx = 0; idx < 5; idx++)
std::cout << "Top buyer" << (idx+1) << ": " << topBuyers[idx] << std::endl;
std::cout << std::endl;
delete [] topBuyers;
代码的下部分是有问题的方法。
string* Analyser::topFiveBuyers()
{
const int sSize = 5;
string calcString[sSize] = {tArray[0].buyerName, tArray[1].buyerName,
tArray[2].buyerName, tArray[3].buyerName, tArray[4].buyerName};
return calcString;
}
0xCCCCCCCC是未初始化的内存[何时以及为什么OS将内存初始化为0xCD,0xDD等malloc/free/new/delete?](http://stackoverflow.com/q/370195/995714) – 2015-04-28 15:44:59