zoukankan      html  css  js  c++  java
  • 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
     之前 
  • 相关阅读:
    js设计模式之 适配器模式与应用场景
    2017版本的IDEA
    JAVA实验六——图形用户界面设计——6-47选择整数计算
    升级apache版本
    基于 PVE + TrueNAS 的私有云配置流程
    基于Win10+VS2019的ceres-solver-2.0.0配置流程
    基于PVE+ROS+LEDE的软路由配置流程
    启动android studio
    vscode配置
    找不到https://raw.githubusercontent.com
  • 原文地址:https://www.cnblogs.com/huapox/p/3299818.html
Copyright © 2011-2022 走看看