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

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

原文:

http://blog.csdn.net/hzyong_c/archive/2009/02/20/3913692.aspx

 

上午写程序时,加入了前些写的一个类,编译时遇到如下错误:
...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

error C2061: syntax error : identifier 'string' 编译时候报错:error C2061: syntax error : identifier ‘string’分析原因:没有加入 #include<string> using namespace std;通常是由于std命名空间引起的 阅读详情

相关推荐

error C2061: syntax error : identifier 'CAMSchedule'

DirectShow中的例子,在编译的过程中经常会出现这样的错误Error 1 error C2061: syntax error : identifier CAMSchedule c:/programfiles/microsoftsdks/windows/v6.0/samples/multimedia/directshow/baseclasses/refclock.h80 这主

jtujtujtu的专栏 6967

error C2061: syntax error : identifier 'THIS_FILE'

今天写个数字图像实验课的mfc代码,里面用到了stl,出现了一堆莫名其妙的错误提示。如下: [quote] error C2091: function returns function d:\program files\microsoft visual studio\vc98\include\new(35) : error C2809: 'operator new' has no formal...

tiger-hu 416

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

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

Welcom to zougangx's blog 2076

C++编译错误syntax error : identifier 'THIS_FILE' 解决方法

你到代码里搜索 THIS_FILE看是不是它定义在别的头文件前面了,如果是,把它们的头文件紧跟到Stdafx.h后面 我遇到过这问题,这样搞定的 今天遇到个编译错误:..\vc98\include\new(35) : error C2061: syntax error : identifier 'THIS_FILE',我的某个.cpp中是这样写的: #include "stda...

weixin_30721077的博客 523

编译过程中弹出new(35) : error C2061: syntax error : identifier 'THIS_FILE'问题的原因及解决方法

http://www.99inf.net/SoftwareDev/VC/27092.htm 原本一直正常的程序,今天编译时突然弹出以下内容c:/program files/microsoft visual studio/vc98/include/new(35) : error C2061: syntax error : identifier THIS_FILEc:/progra

james@BJ的专栏 3239

C2061 语法错误: 标识符“ITEM_CHECK”

是 Microsoft Visual Studio 中的一个编译错误,它表示“语法错误:标识符 'identifier' 未定义”。这个错误通常发生在编译器找不到你尝试使用的变量、函数、类型或其他标识符的定义时。如果你在Visual Studio中遇到这个错误,IDE通常会为你提供足够的信息来定位问题发生的位置。你可以查看错误列表窗口,找到。的详细信息,然后跳到相应的代码行进行修复。部分可以理解为报警信息。

m0_50040537的博客 1687

return function和return function()的区别

function a() { console.log('我是第一个函数'); } //returns undefined function b() { console.log('我是第二个函数');...

碉堡飞哥的博客 4177

A function returns function

class CMemFunc{public:    CMemFunc();    virtual ~CMemFunc(){};    typedef void (CMemFunc::*PesudoAction)();    typedef CMemFunc::PesudoAction PACTION;    typedef PACTION (CMemFunc::*Action)();    typ

Trending Up... 1212

c语言中错误c2061,C ++:语法错误C2061:意外的标识符(C++: Syntax error C2061: Unexpected identifier)...

C ++:语法错误C2061:意外的标识符(C++: Syntax error C2061: Unexpected identifier)这行代码有什么问题?bar foo(vector ftw);它产生error C2061: syntax error: identifier 'vector'What's wrong with this line of code?bar foo(vector f...

weixin_39822629的博客 3089

VC6提示 error C2061: syntax error : identifier 'THIS_FILE' 错误的解决办法

今天在编译一段以前写的代码时候,遇到了这样的错误--------------------Configuration: AppSharePlugin - Win32 Debug--------------------Compiling...AppSharePluginModule.cppd:\program files\microsoft visual studio\vc98\include\new...

weixin_30394669的博客 654

VC里的"#define new DEBUG_NEW"

载地址:http://www.cnblogs.com/imapla/archive/2012/09/03/2668859.html 以下代码常常在一个类文件的开头出现,是什么意思呢? #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif

blacet的专栏 869

DEBUG_NEW 导致编译失败的问题

error C2665: 'operator new' none of the 5 overloads could convert all the argument types

水晶鞋 1244

error C2061: syntax error : identifier 'BinryTreeNode'

1>d:\我的文档\visual studio 2005\projects\tree\tree\tree.h(23) : error C2061: syntax error : identifier 'BinryTreeNode' 1>        d:\我的文档\visual studio 2005\projects\tree\tree\tree.h(77) : see reference

苍苍尘渺天的专栏 1076
上一篇: 【转载】TinyXML(C++ XML解析库)
下一篇: 关于部分自定义静态库(*.lib)在Pocket PC不能使用的问题
code09
博客等级 码龄18年 31粉丝 56原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值