error C2061: syntax error : identifier 'THIS_FILE'

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

d:\program files\microsoft visual studio\vc98\include\new(35) : see declaration of 'new'
d:\program files\microsoft visual studio\vc98\include\new(41) : error C2061: syntax error : identifier 'THIS_FILE'
d:\program files\microsoft visual studio\vc98\include\new(42) : error C2091: function returns function

d:\program files\microsoft visual studio\vc98\include\new(35) : see declaration of 'new'
d:\program files\microsoft visual studio\vc98\include\new(42) : error C2809: 'operator new' has no formal parameters
d:\program files\microsoft visual studio\vc98\include\new(42) : error C2065: '_P' : undeclared identifier
d:\program files\microsoft visual studio\vc98\include\memory(16) : error C2061: syntax error : identifier 'THIS_FILE'
d:\program files\microsoft visual studio\vc98\include\memory(17) : error C2091: function returns function

d:\program files\microsoft visual studio\vc98\include\memory(16) : see declaration of 'new'
d:\program files\microsoft visual studio\vc98\include\memory(17) : error C2809: 'operator new' has no formal parameters
d:\program files\microsoft visual studio\vc98\include\memory(20) : error C2954: template definitions cannot nest


不过还好,google一下就出来了,嗯。我们去官网看看去:
http://support.microsoft.com/default.aspx?scid=kb;en-us;143207
我的情况应该属于case2,
也就是这个:
引用

Case Two
In addition, you may get this different set of errors:
{include directory}\new.h(80) : error C2061: syntax error : identifier 'THIS_FILE'
{include directory}\new.h(80) : error C2091: function returns function
{include directory}\new.h(80) : error C2809: 'operator new' has no formal parameters#endif
{include directory}\new.h(80) : error C2065: 'ptr' : undeclared identifier

呵呵,然后看解决办法啊:
引用
The second set of errors occurs if you add the STL include directive after the following definitions and do not include New.h among your include directives:
   #ifdef _DEBUG
   #define new DEBUG_NEW
   #undef THIS_FILE
   static char THIS_FILE[] = __FILE__;
   #endif

Including New.h will work around this problem as well. Note that these definitions are no longer necessary in MFC code and can be deleted.

可以这样解决:
#include <vector>
#include <algorithm>
using namespace std;
/*
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
*/

把std的那些东西放到mFC声明的代码的前面,或者直接注释掉MFC代码。rebulid all。pass。

你可能感兴趣的:(Microsoft,Google,mfc)