我有一个函数。在这我试图复制一个结构到另一个相同类型的结构。这个结构作为向量存储在CProjectData
类中。 当我尝试复制内容时,它崩溃。的代码段如下所示:将矢量复制到另一个时发生崩溃
void CProjectData::send()
{
struct EmuComputerData tempStruct;
//ignore this line
m_pClient->GetTeleSend()->CreateHeader(GetFbMsgType(m_dwCmdId));
//ignore this line
CProjectData* pProjectdata = (CProjectData*) m_pClient->GetTeleSend()->AddBuffer(sizeof(CProjectData));
//ignore this line
pProjectdata->m_wErrorCode = m_wErrorCode;
//ignore this line
strcpy_s(pProjectdata->m_szProjectName, MAX_PROJECTNAME_LENGTH + 1, m_szProjectName);
vector<struct EmuComputerData>::iterator iter;
iter = m_emuComputerData.begin();
for (; iter != m_emuComputerData.end(); iter++)
{
tempStruct.wEmuComputerNo = (*iter).wEmuComputerNo;
tempStruct.dwIPAddress = (*iter).dwIPAddress;
tempStruct.wPCCount = (*iter).wPCCount;
vector<WORD>::iterator apIter;
apIter = (*iter).apNumbers.begin();
for (; apIter != (*iter).apNumbers.end(); apIter++)
{
tempStruct.apNumbers.push_back(*apIter);
}
//crashes after executing this line
pProjectdata->m_emuComputerData.push_back(tempStruct);
}
}
m_emuComputerData
被声明为
vector<struct EmuComputerData> m_emuComputerData;
在ProjectData
类。
这是一个结构,它又包含一个向量。
struct EmuComputerData
{
WORD wPCCount;
WORD wEmuComputerNo;
DWORD dwIPAddress;
vector<WORD> apNumbers;
};
这里是调用堆栈:它崩溃,当我TRU复制vector<WORD> apNumbers
。我相信我在复制这个矢量的时候正在做一些愚蠢的事情。
msvcr90d.dll!operator delete(void * pUserData=0xcdcdcdcd) Line 52 + 0x3 bytes C++
EmuDiagnosticsService.exe!std::allocator<EmuComputerData>::deallocate(EmuComputerData * _Ptr=0xcdcdcdcd, unsigned int __formal=0) Line 140 + 0x9 bytes C++
EmuDiagnosticsService.exe!std::vector<EmuComputerData,std::allocator<EmuComputerData> >::_Insert_n(std::_Vector_const_iterator<EmuComputerData,std::allocator<EmuComputerData> > _Where={wPCCount=??? wEmuComputerNo=??? dwIPAddress=??? ...}, unsigned int _Count=1, const EmuComputerData & _Val={...}) Line 1202 C++
EmuDiagnosticsService.exe!std::vector<EmuComputerData,std::allocator<EmuComputerData> >::insert(std::_Vector_const_iterator<EmuComputerData,std::allocator<EmuComputerData> > _Where={wPCCount=??? wEmuComputerNo=??? dwIPAddress=??? ...}, const EmuComputerData & _Val={...}) Line 878 C++
EmuDiagnosticsService.exe!std::vector<EmuComputerData,std::allocator<EmuComputerData> >::push_back(const EmuComputerData & _Val={...}) Line 823 + 0x58 bytes C++
> EmuDiagnosticsService.exe!CProjectData::send() Line 574 C++
EmuDiagnosticsService.exe!CEmuDiagTCPServer::Send() Line 374 + 0xf bytes C++
EmuDiagnosticsService.exe!StartTCPServer(void * dummy=0x00000000) Line 251 C++
感谢
Nipun
是否有可能'pProjectdata'实际上是'this'?这意味着你正在推进你正在阅读的同一个矢量,这将导致麻烦 –