push_back的问题
同样的数据结构,为什么类中的数据push_back就出错,而在函数里声明的push_back就不出错呢?
- C/C++ code
// 头文件中的声明std::vector<C3dMaterial*> m_MaterialList; bool SomeClass::LoadMtlData(CString filename){ std::vector<C3dMaterial*> ab; m_TextureMapArray.clear(); m_MaterialList.clear(); CStdioFile mFile; CFileException e; if (!mFile.Open(filename, CFile::modeRead|CFile::typeText, &e)) { TCHAR szError[1024]; e.GetErrorMessage(szError, 1024); AfxMessageBox(szError); return false; } mFile.SeekToBegin(); CString strTemp; int tempIndex; CString mtlName; CString photoName; C3dMaterial* pcurMtl=NULL; float color[3]; while (mFile.ReadString(strTemp)) { strTemp.Trim(); switch(char(strTemp.GetAt(0))) { case '#': break; case 'n': { tempIndex = strTemp.GetLength(); mtlName = strTemp.Right(tempIndex-7); pcurMtl = C3dMaterial::Create(mtlName, 0.f, 0.f, 0.f, 1.00f, 0.f, 0.f, 0.f, 1.00f, 0.f, 0.f, 0.f, 1.00f, 0.f, 0.f, 0.f, 1.00f, 0.0f, 0.0f, 0.0f, 1.f); ab.push_back(pcurMtl); //不出错 m_MaterialList.push_back( pcurMtl ); //出错? }[解决办法]
- C/C++ code
// 头文件中的声明std::vector<C3dMaterial*> m_MaterialList;
[解决办法]
出错说明你没有写对operator =,自己检查写没写好。
[解决办法]
- C/C++ code
non-local static object 初始化顺序问题,4楼解释的很清楚,你那不叫声明,你又定义了,然后再CPP文件中导致没有初始化,用extern声明过来就不一样