您的位置:首页 > 其它

C1020: 意外的 #endif

2015-06-18 11:07 387 查看
对于“ fatal error C1020: 意外的 #endif ”错误,原因大致如下:



如果使用了预编译头,VC会在所有CPP文件里寻找

#include "stdafx.h "

在找到这行代码之前,VC会忽略所有代码。

也就是说,下例中,VC 找到第二行 #include "stdafx.h" 之前,会将第一行#ifndef _EiC 忽略掉,因此出现“意外的 #endif”找不到匹配。

#ifndef _EiC

#include "stdafx.h"

#include "cv.h"

#include "cxcore.h"

#include "highgui.h"

#endif



将上例修改为如下所示即可。

#include "stdafx.h"

#ifndef _EiC

#include "cv.h"

#include "cxcore.h"

#include "highgui.h"

#endif



PS. :#ifndef V.S. #ifdef



#ifndef避免编译时多个相同头文件的重复编译及避免冲突。



PPS. :

所有的CPP实现文件第一条语句都是:#include "stdafx.h"

因为编译器认为,所有在指令#include "stdafx.h"前的代码都是预编译的,它跳过#include "stdafx. h"指令,使用projectname.pch编译这条指令之后的所有代码。

转自:http://blog.csdn.net/zhmyy/article/details/5331984
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: