当前位置:首页 > 服务端 > C2061: syntax error : identifier 'THIS_FILE'

C2061: syntax error : identifier 'THIS_FILE'

       关于宏与头文件错误的冲突问题的解决
           宏与头文件错误的冲突问题
程序如下:
// SisSocket.cpp : implementation file
//
#include "stdafx.h"
#include "DataServer.h"
#include "SisSocket.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "DataServerDlg.h"
//...其他代码
// DataServerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DataServer.h"
#include "DataServerDlg.h"
#include "EzDnaApi.h"
#include "EzDnaServApi.h"
#include "SafeArrayHelper.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//...其他代码
编译错误如:
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
等类似错误
双击错误
inline void *__cdecl operator new(size_t, void *_P)
{return (_P);
经指点,将
// SisSocket.cpp : implementation file
//
#include "stdafx.h"
#include "DataServer.h"
#include "SisSocket.h"
#include "DataServerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//...其他代码
问题解决,出在new重定义上
注:THIS_FILE为static char[],在debug时内容为本文件路径,供输出错误信息使用。
//-----------------------------------------------------------------------
在文件test7Dlg.cpp当有如下定义时: 
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <vector>
就会出现如下错误:
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'
c:\program files\microsoft visual studio\vc98\include\new(41) : error C2061: syntax error : identifier 'THIS_FILE'
c:\program files\microsoft visual studio\vc98\include\new(42) : error C2091: function returns function
c:\program files\microsoft visual studio\vc98\include\new(42) : error C2556: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,void *)' : overloaded function differs only by return type from 'void *(__cdecl *__cdecl operator new(void))(unsig
ned int)'
        c:\program files\microsoft visual studio\vc98\include\new(35) : see declaration of 'new'
c:\program files\microsoft visual studio\vc98\include\new(42) : error C2809: 'operator new' has no formal parameters
c:\program files\microsoft visual studio\vc98\include\new(42) : error C2065: '_P' : undeclared identifier
c:\program files\microsoft visual studio\vc98\include\memory(16) : error C2061: syntax error : identifier 'THIS_FILE'
c:\program files\microsoft visual studio\vc98\include\memory(17) : error C2091: function returns function
c:\program files\microsoft visual studio\vc98\include\memory(17) : error C2784: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,class std::allocator<`template-parameter257'> &)' : could not deduce template argument for 'void *(__cdecl *)(u
nsigned int,class std::allocator<_Ty> &)' from 'void *(__cdecl *)(unsigned int)'
c:\program files\microsoft visual studio\vc98\include\memory(17) : error C2785: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,class std::allocator<`template-parameter257'> &)' and 'void *(__cdecl *__cdecl operator new(void))(unsigned int
)' have different return types
        c:\program files\microsoft visual studio\vc98\include\memory(16) : see declaration of 'new'
c:\program files\microsoft visual studio\vc98\include\memory(17) : error C2809: 'operator new' has no formal parameters
c:\program files\microsoft visual studio\vc98\include\memory(20) : error C2954: template definitions cannot nest
Error executing cl.exe.
解决办法:
 1。把#include <vector>语句放在test7Dlg.h文件中
 2。把定义顺序颠倒下,如下所示:
#include <vector>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
原因:
 VC6是可以支持的,不过头文件的声明
 #include <list>
 using namespace std;
 要在系统生成的代码
 #ifdef _DEBUG
 #define new DEBUG_NEW
 #undef THIS_FILE
 static char THIS_FILE[] = __FILE__;
 #endif
 之前 

作者:linux,dev
来源链接:https://www.cnblogs.com/huapox/archive/2011/06/01/3299818.html

版权声明:
1、Java侠(https://www.javaxia.com)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaxia.com/server/124965.html

标签: syntax error
分享给朋友:

“C2061: syntax error : identifier 'THIS_FILE'” 的相关文章