编程常见错误

 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);
}

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值