error C2061: syntax error : identifier 'THIS_FILE'

本文解决了一个特定的编译错误问题,该问题出现在使用STL的项目中,尤其是在混合使用了VC6自动生成的代码和STL头文件的情况下。通过调整STL头文件的引入位置,成功解决了编译时出现的多个错误。

编译时遇到如下错误:

--------------------Configuration: epupserver - Win32 Debug--------------------
Compiling...
epupserverDlg.cpp
C:/Program Files/Microsoft Visual Studio/VC98/INCLUDE/new(35) : error C2061: syntax error : identifier 'THIS_FILE'
C:/Program Files/Microsoft Visual Studio/VC98/INCLUDE/new(35) : error C2091: function returns function
C:/Program Files/Microsoft Visual Studio/VC98/INCLUDE/new(35) : error C2809: 'operator new' has no formal parameters
C:/Program Files/Microsoft Visual Studio/VC98/INCLUDE/new(36) : error C2061: syntax error : identifier 'THIS_FILE'
C:/Program Files/Microsoft Visual Studio/VC98/INCLUDE/new(37) : error C2091: function returns function
C:/Program Files/Microsoft Visual Studio/VC98/INCLUDE/new(37) : error C2556: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,const struct std::nothrow_t &)' : overloaded function differs only by return type from 'void *(__cdecl *__cdecl op
erator new(void))(unsigned int)'
        C:/Program Files/Microsoft Visual Studio/VC98/INCLUDE/new(35) : see declaration of 'new'
Error executing cl.exe.

epupserver.exe - 6 error(s), 0 warning(s)

 

 

解决方法:
类中用了STL,而包含STL头文件的时候写的位置如下所示:
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

……………………

 

#include   <iostream>
#include   <string>
using   namespace   std;


上网搜索一遍,发现出现这些错误与STL头文件和VC6在CPP文件里生成的几行代码有关,STL头文件是指以下几行:

#include   <iostream>
#include   <string>
using   namespace   std;


VC6在CPP文件里生成的几行代码指以下几行:
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

 

不知道谁写的代码,将

#include   <iostream>
#include   <string>
using   namespace   std;

写在cpp文件快结束的几个函数之前,于是将这几行拖到前面。
#include   <iostream>
#include   <string>
using   namespace   std;

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

 

 

我用了上述你给我提供的代码,出现了下列问题,请根据这些问题修改代码并且将修改后的完整代码发给我 222.c(107): error C141: syntax error near 'unsigned', expected '__asm' 222.c(107): error C141: syntax error near '}', expected ';' 222.c(108): error C202: 'days_in_month': undefined identifier 222.c(110): error C202: 'days_in_month': undefined identifier 222.c(169): error C141: syntax error near 'unsigned', expected '__asm' 222.c(169): error C202: 'LSB': undefined identifier 222.c(170): error C141: syntax error near 'unsigned', expected '__asm' 222.c(170): error C202: 'MSB': undefined identifier 222.c(171): error C202: 'MSB': undefined identifier 222.c(286): error C141: syntax error near 'unsigned', expected '__asm' 222.c(286): error C202: 'seconds': undefined identifier 222.c(287): error C141: syntax error near 'unsigned', expected '__asm' 222.c(287): error C202: 'ms': undefined identifier 222.c(291): error C202: 'seconds': undefined identifier 222.c(476): error C141: syntax error near 'static', expected '__asm' 222.c(476): error C202: 'temp_counter': undefined identifier 222.c(477): error C202: 'temp_counter': undefined identifier 222.c(478): error C202: 'temp_counter': undefined identifier 222.c(491): error C141: syntax error near 'static', expected '__asm' 222.c(491): error C202: 'ms_counter': undefined identifier 222.c(492): error C141: syntax error near 'static', expected '__asm' 222.c(492): error C202: 'sec_counter': undefined identifier 222.c(494): error C202: 'ms_counter': undefined identifier 222.c(503): error C202: 'ms_counter': undefined identifier 222.c(504): error C202: 'ms_counter': undefined identifier Target not created.
06-21
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值