1.在寫類的成員函數的時候,忘記在成員函數前寫類名字,導致類中的數據成員不可見,報錯
QVector3d CalFaceNormal(const int f0, const int f1, const int f2, QVector3d &faceNormal)
{
QNormal n0, n1, n2;
n0 = normals.at(f0);
n1 = normals.at(f1);
n2 = normals.at(f2);
faceNormal = (n0+n1+n2)/3.0;
return faceNormal;
}
上面這麼寫會導致normals不可見,報錯爲:
error C2065: 'normals' : undeclared identifier
因此,正確的寫法應該爲:
QVector3d QScene::CalFaceNormal(const int f0, const int f1, const int f2, QVector3d &faceNormal)
2.在用三角形的頂點索引表示面的時候,記得經常會在調用頂點時頂點的索引要減1.
3.當從其他程序中,轉換的時候,(比如把VC6.0的代碼轉換到VC2005的代碼,可能原來程序是WINDOWS程序,而轉換後應該是控制檯程序),就會出現error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup的錯誤,那麼更改Linker->System->SubSystem 即可.
4.在用ofstream輸出的時候,經常發生錯誤error C2065: 'ofstream' : undeclared identifier 主要原因是忘記寫using namespace std;
5.在用到stl的vector等容器時,會出現如下錯誤:
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
是因爲在用到vector的地方沒加 using namespace std;
上面的錯誤也可能是因爲在用到一個類的時候,雖然include了該文件,但是仍然要在前面說一下:
class CLand;
6.在使用vector<someclass>時,如果使用push_back函數出現異常,很可能是你自己寫的someclass沒有寫拷貝構造函數!另外,如果是自己寫的類someclass,這個類的析構函數一定要是虛函數。
7.error C2259: cannot instantiate abstract class
是由於自己在基類中聲明瞭純虛函數,而在繼承類中沒有對其實現。
8.在調用DLL時,常點“取消”或“下一步”後就會出現內存出錯等等錯誤,原因是下面代碼中,CSheet sheet(_T("name"));要有_T()
extern "C" __declspec(dllexport) void LightCalShow()
{
HINSTANCE save_hInstance = AfxGetResourceHandle();
AfxSetResourceHandle(theApp.m_hInstance);
AFX_MANAGE_STATE(AfxGetAppModuleState());
CSheet sheet(_T("name"));
sheet.DoModal();
AfxSetResourceHandle(save_hInstance);
}