1>d:\mt\mtupsmonitor\mtupsmonitor\Common.h(63): error C2146: 语法错误: 缺少“;”(在标识符“CString2string”的前面)
1>d:\mt\mtupsmonitor\mtupsmonitor\Common.h(63): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\mt\mtupsmonitor\mtupsmonitor\Common.h(63): warning C4183: “CString2string”: 缺少返回类型;假定为返回“int”的成员函数
1>d:\mt\mtupsmonitor\mtupsmonitor\Common.h(64): error C2061: 语法错误: 标识符“string”
1>d:\mt\mtupsmonitor\mtupsmonitor\Common.h(72): error C2143: 语法错误 : 缺少“;”(在“<”的前面)
1>d:\mt\mtupsmonitor\mtupsmonitor\Common.h(72): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\mt\mtupsmonitor\mtupsmonitor\Common.h(72): error C2238: 意外的标记位于“;”之前
总结了一下,主要有以下原因:
1、(此情况经常出现在大型工程项目中)如果存在两个类的头文件a.h和b.h,在a.h中有这样的语句:#include "b.h",在b.h文件中有这样的语句:#include "a.h" 且在一个类中有另一个类的对象时 那么就会出现这样的错误。
2、没有包含要定义的类的头文件。
3、项目中少加了宏定义,导致头文件重复定义或相应宏无法识别。
4、函数无返回类型的时候,可能也会导致这样的错误。
5、当有多个头文件时,顺序写反也可能导致相关的错误,其根本是头文件中的预编译语句被隐去了。
比如:
#include <stdio.h>
#include <Windows.h> 第二个
#include <WinCrypt.h> 第三个
#include <string.h>如果把第二个和第三个写反,一个宏定义就被#if给注了,就会出现类似错误