覆盖"new"时编译错误
Compiling error when overwriting "new"
我正在尝试控制代码中的mem泄漏。在我的常规头文件中,我添加了以下代码:
// You may need to locate mem leaks
#define ZEL_CHECK_MEMORY_LEAKS
#ifdef ZEL_CHECK_MEMORY_LEAKS
#define _CRTDBG_MAP_ALLOC
#include <cstdlib>
#include <crtdbg.h>
#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
#endif // _DEBUG
#define zelInitMemoryCheck()
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF)
#else
#define zelInitMemoryCheck()
#endif //ZEL_CHECK_MEMORY_LEAKS
如果我添加此代码,则会出现以下编译错误:
1>c:archivos de programamicrosoft visual studio 9.0vcincludexlocmon(283) : error C2061: syntax error : identifier '_DebugHeapTag_func'
1> c:archivos de programamicrosoft visual studio 9.0vcincludexlocmon(281) : while compiling class template member function 'size_t std::moneypunct<_Elem,_Intl>::_Getcat(const std::locale::facet **,const std::locale *)'
1> with
1> [
1> _Elem=char,
1> _Intl=true
1> ]
1> c:archivos de programamicrosoft visual studio 9.0vcincludexlocmon(908) : see reference to class template instantiation 'std::moneypunct<_Elem,_Intl>' being compiled
1> with
1> [
1> _Elem=char,
1> _Intl=true
1> ]
此外,在我的源代码中,我包含以下内容:
#include "core/zelCoreLib.h"
#include <boost/shared_ptr.hpp>
其中 mem 泄漏控制代码位于 zelCoreLib.h 中
对于那些没有VC9.0的人来说,这是"失败"的代码
static size_t __CLRCALL_OR_CDECL _Getcat(const locale::facet **_Ppf = 0,
const locale *_Ploc = 0)
{ // return locale category mask and construct standard facet
if (_Ppf != 0 && *_Ppf == 0)
*_Ppf = _NEW_CRT moneypunct<_Elem, _Intl>(
_Locinfo(_Ploc->name()), 0, true);
return (_X_MONETARY);
}
它似乎是字符串和区域设置设施的一部分。另外,作为附加信息,我使用 Lua 和 LuaBind 库
欢迎任何帮助
你有一个#define new
. new
是一个关键字,如果在标准库中包含任何标头,#define
它会导致未定义的行为。 例如,标准库几乎肯定会在某些地方使用放置新放置,并且您的宏将导致任何放置新放置的使用中断。 它还会导致任何特定于类的new
中断,库也可能使用这些。 您不能重新定义关键字并期望任何内容都有效。
相关文章:
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- std::is_base_of表示ctor编译错误
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- Qt Cmake 错误编译"GuiSupportQt not found"
- Opengl 精度转换错误编译错误 E0415
- 库将ARM架构错误编译为架构X64
- RT 音频 Mac 错误 g++ 编译错误
- 错误编译Boost.log
- 错误编译QT创建者 / QT窗口小部件示例
- 错误编译MIPS32
- Visual Studio 2013 中的错误(编译和运行代码)
- 链接错误编译qt项目在visual 2010
- 无法用模板错误编译nsgmls
- 奇怪的错误.编译失败
- 如果有人调用c++中的方法,则强制错误(编译时)
- 来自autoconf测试的错误编译命令
- 时间限制超出错误C++编译
- SFML 2.3 和 CodeBlocks 错误编译