编译时遇到如下错误error C2061: syntax error : identifier 'THIS_FILE'

解决STL与VC6编译错误的技巧
本文详细介绍了在使用STL与VC6进行C++开发时遇到的编译错误问题,并提供了有效解决方案。重点在于正确处理STL头文件与VC6自动生成的代码之间的顺序问题,确保代码顺利编译。

...error C2061: syntax error : identifier 'THIS_FILE'
.../new(35) : error C2091: function returns function
.../new(35) : error C2809: 'operator new' has no formal parameters
.../new(36) : error C2061: syntax error : identifier 'THIS_FILE'
.../new(37) : error C2091: function returns function

 

解决方法:

新加入的类是CSelectServer,该类里用到了STL,该类在HouServer.cpp里调用,在HouServer.cpp包含CSelectServer.h文件时写成了如下这样:
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "SelectServer.h"
上网搜索一遍,发现出现这些错误与STL头文件和VC6在CPP文件里生成的几行代码有关,STL头文件是指以下几行:

#pragma warning (disable:4786)
#include <list>
using namespace std;

VC6在CPP文件里生成的几行代码指以下几行:

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
STL头文件要写在VC6在CPP文件里生成的几行代码之前,谨记!我的 "SelectServer.h"文件里包含了STL头文件,当在其它cpp文件里包含"SelectServer.h"文件时一定要将#include"SelectServer.h"放在VC6生成的那几行代码之前!所以改成下面这样就编译通过。
#include "SelectServer.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

在你所给的代码中。出现了以下问题,怎么修改呢 SOFT_I2C.H(3): error C202: 'P2': undefined identifier SOFT_I2C.H(4): error C202: 'P2': undefined identifier SOFT_I2C.H(9): error C141: syntax error near 'dat', expected ')' SOFT_I2C.H(10): error C129: missing ';' before 'I2C_ReadByte' compiling DHT11.c... 新建文件夹\DHT11.c(1): warning C318: can't open file 'DHT11.h' 新建文件夹\DHT11.C(3): error C141: syntax error near 'n', expected ')' 新建文件夹\DHT11.C(4): error C202: 'n': undefined identifier compiling DS1302.c... 新建文件夹\DS1302.H(5): error C141: syntax error near 'uint8_t' 新建文件夹\DS1302.H(5): error C129: missing ';' before 'year' compiling OLED.c... SOFT_I2C.H(3): error C202: 'P2': undefined identifier SOFT_I2C.H(4): error C202: 'P2': undefined identifier SOFT_I2C.H(9): error C141: syntax error near 'dat', expected ')' SOFT_I2C.H(10): error C129: missing ';' before 'I2C_ReadByte' 新建文件夹\OLED.c(2): warning C318: can't open file 'font.h' compiling main.c... 新建文件夹\main.c(1): warning C318: can't open file 'STC12C5A60S2.H' 新建文件夹\main.c(2): warning C318: can't open file 'DHT11.h' SOFT_I2C.H(3): error C202: 'P2': undefined identifier SOFT_I2C.H(4): error C202: 'P2': undefined identifier SOFT_I2C.H(9): error C141: syntax error near 'dat', expected ')' SOFT_I2C.H(10): error C129: missing ';' before 'I2C_ReadByte' compiling ADC.c... 新建文件夹\ADC.H(4): error C129: missing ';' before 'ADC_Read' compiling soft_i2c.c... SOFT_I2C.H(3): error C202: 'P2': undefined identifier SOFT_I2C.H(4): error C202: 'P2': undefined identifier SOFT_I2C.H(9): error C141: syntax error near 'dat', expected ')' SOFT_I2C.H(10): error C129: missing ';' before 'I2C_ReadByte' 目标未创建
06-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值