编程常见错误
2009-03-03 14:23
316 查看
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);
}
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);
}
相关文章推荐
- socket编程常见错误总结
- 编程过程中常见的错误及解决方法
- PHP 编程中 10 个最常见的错误,你犯过几个?
- 常见编程错误-新手(更新中。。。)
- 利用GetLastError()获得的socket编程中常见错误
- Linux编程常见错误及解决方案
- C#与MATLAB混合编程常见错误
- 几个常见的编程错误
- 【读书笔记】C程序中常见的内存操作有关的典型编程错误
- 编程相关,OJ题常见错误,及做题总结
- 编程基础-文字编码-字符集/编码方式/常见乱码错误
- Python常见编程错误和陷阱
- C语言编程常见错误与解决办法
- android编程常见错误集锦
- C/C++编程常见问题(2)-错误打印64位长整数
- Java编程最差实践(常见编程错误典范)
- 一些常见的并发编程错误
- c++常见编程错误---《面向对象程序设计 c++语言描述》
- 10大SQL编程常见错误(Ten Common SQL Programming Mistakes)
- 【C++编程规范】编程需要避免的常见错误