我有以下课程:
class clsJoinFeeder
{
public:
vector<vector<unsigned char> > UnsignedChars;
};
现在我想在类中添加一个无符号字符向量。我试着这样做:
void CBinLoader::LoadJoinFeaturesFromCompiledDat(clsJoinFeeder &uJoinFeeder)
{
for (unsigned int y=0;y<2;y++)
{
for (unsigned int x=0;x<17;x++)
{
pLoadSmallFloatMap(uJoinFeeder);
pLoadBigUnsignedCharMap(uJoinFeeder);
}
}
}
void CBinLoader::pLoadBigUnsignedCharMap(clsJoinFeeder &uJoinFeeder)
{
unsigned int iItemsCount = 0;
fread(&iItemsCount,sizeof(unsigned int),1,m_infile);
unsigned long iByteSizeActualData = 0;
fread(&iByteSizeActualData,sizeof(unsigned long),1,m_infile);
vector<unsigned char>nChars;
nChars.resize(iItemsCount+1);
fread(&nChars[0],iByteSizeActualData,1,m_infile); //works fine. nChars is correctly filled
uJoinFeeder.UnsignedChars.push_back(nChars); //here the crash occurs
}
它编译得很好,但在运行时它崩溃并在行中出现堆分配错误:
uJoinFeeder.UnsignedChars.push_back(nChars);
我能做些什么来解决这个问题?我什至没有看到我的错误。
编辑:
感谢您的帮助!正如 Kühl 先生所说,“iByteSizeActualData”是错误的。