【发布时间】:2011-04-05 15:46:04
【问题描述】:
我使用这个 Debug.h 文件作为我要调试内存泄漏的文件的最后一个#include。然后使用 _CrtDumpMemoryLeaks();将其转储到我的输出中。这对大多数文件都适用,但是当我将其包含在某些文件中时,会出现以下错误。看起来它与 boost::unorderer_map .. 但我可以将我的 Debug.h 包含到 .h 文件中,我在其中定义和使用 unordered_map 没有任何错误.. 当我得到错误时将它包含在我什至不使用它的 .h 文件中..
#ifndef DEBUG_H
#define DEBUG_H
#ifdef _DEBUG
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif
#endif
1>d:\uni\ict312\labproject\labproject\inc\boost\unordered\detail\fwd.hpp(351):错误 C2059:语法错误:'(' 1> d:\uni\ict312\labproject\labproject\inc\boost\unordered\detail\fwd.hpp(350) : 在编译类模板成员函数'void boost::unordered_detail::hash_buffered_functions::construct(bool,const H &,常量 P &)' 1> 与 1> [ 1> H=升压::哈希, 1> P=std::equal_to 1>] 1> d:\uni\ict312\labproject\labproject\inc\boost\unordered\detail\fwd.hpp(432) : 参见正在编译的类模板实例化 'boost::unordered_detail::hash_buffered_functions' 的参考 1> 与 1> [ 1> H=升压::哈希, 1> P=std::equal_to 1>] 1> d:\uni\ict312\labproject\labproject\inc\boost\unordered\detail\fwd.hpp(572) : 请参阅正在编译的类模板实例化 'boost::unordered_detail::hash_table' 的参考 1> 与 1> [ 1> T=boost::unordered_detail::map,std::equal_to,std::allocator>> 1>] 1> d:\uni\ict312\labproject\labproject\inc\boost\unordered\unordered_map.hpp(98) : 请参阅正在编译的类模板实例化 'boost::unordered_detail::hash_unique_table' 的参考 1> 与 1> [ 1> T=boost::unordered_detail::map,std::equal_to,std::allocator>> 1>] 1> d:\uni\ict312\labproject\labproject\inc\collisiondetector.h(15) : 请参阅正在编译的类模板实例化 'boost::unordered_map' 的参考 1> 与 1> [ 1> K=无符号整数, 1> T=物理对象 1>]
【问题讨论】:
-
也许我有些困惑,但据我所知,您在使用 _CrtDumpMemoryLeaks() 时不需要需要任何 DEBUG_NEW。您还想正确格式化错误消息!
-
Martin:_CrtDumpMemoryLeaks 在没有 DEBUG_NEW 的情况下工作,但它不显示文件名和行号,只显示内存地址。
标签: c++ visual-studio-2008 mfc boost memory-leaks