语法错误 : 缺少“;”(在标识符“ContextRecord”的前面)

来源:互联网 发布:闲鱼钓鱼源码 编辑:程序博客网 时间:2024/05/31 15:18

一个简单的问题:

头文件为:

#include <iostream>
#include "stdlib.h"
#include <math.h>
#include <windef.h>
#include <winbase.h>

编译后产生如下错误:

d:\program files\microsoft visual studio\vc98\include\winnt.h(3143) : error C2146: syntax error : missing ';' before identifier 'ContextRecord'

d:\program files\microsoft visual studio\vc98\include\winnt.h(3143) : error C2501: 'PCONTEXT' : missing storage-class or type specifiers
d:\program files\microsoft visual studio\vc98\include\winnt.h(3143) : error C2501: 'ContextRecord' : missing storage-class or type specifiers
d:\program files\microsoft visual studio\vc98\include\winbase.h(715) : error C2146: syntax error : missing ';' before identifier 'LPCONTEXT'

d:\program files\microsoft visual studio\vc98\include\winbase.h(715) : fatal error C1004: unexpected end of file found

这里的是因为PCONTEXT未得到定义,而且错误产生在windef.h和winbase.h中,且打开头文件没有发现人为改动产生的错误。


修改:

第一次尝试将winbase.h放到windef.h之前,结果产生更多错误,因此类型符的定义不在这两个文件中。

因此想到是不是缺少头文件的问题,于是在iostream的下面加上加上了不同的头文件,发现windows.h的时候编译可以通过,由此可知windows.h中定义winbase.h和windef.h的一些东西。

(这里如果将windows.h放到winbase.h的下面,错误又会出现)

于是查了一下windows.h,可以看到:

WINDOWS.H是一个最重要的头文件,它包含了其他Windows头文件,这些头文件的某些也包含了其他头文件。这些头文件中最重要的和最基本的是:
WINDEF.H 基本数据类型定义。
WINNT.H 支持Unicode的类型定义。
WINBASE.H Kernel(内核)函数。
WINUSER.H 用户界面函数。
WINGDI.H 图形设备接口函数
因此在后面用到这些头文件时,需要以windows.h为开始。

原创粉丝点击