编译时遇到如下错误:
...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
原因和解决方法:
发现类中是用到了STL,而包含STL头文件的时候写的位置如下所示:
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <string>
using namespace std;
上网搜索一遍,发现出现这些错误与STL头文件和VC6在CPP文件里生成的几行代码有关,STL头文件是指以下几行:
#pragma warning (disable:4786)
#include <string>
using namespace std;
VC6在CPP文件里生成的几行代码指以下几行:
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
STL头文件要写在VC6在CPP文件里生成的几行代码之前,切记!改成如下所示即可编译通过。
#include <string>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif