views:

32

answers:

1

Hi,

I use this Debug.h file that I include as the last #include of the files where I want to debug for memory leaks. Then using _CrtDumpMemoryLeaks(); to dump it to my output.. This works fine for most files, but when I include it in some files I get the error below. It looks like it got to do with the boost::unorderer_map<> .. but I can include my Debug.h into .h files where I define and use the unordered_map<> without any errors.. and I get the error when I include it into .h files where I dont even use it aswell..

#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) : error C2059: syntax error : '(' 1> d:\uni\ict312\labproject\labproject\inc\boost\unordered\detail\fwd.hpp(350) : while compiling class template member function 'void boost::unordered_detail::hash_buffered_functions::construct(bool,const H &,const P &)' 1> with 1> [ 1> H=boost::hash, 1> P=std::equal_to 1> ] 1> d:\uni\ict312\labproject\labproject\inc\boost\unordered\detail\fwd.hpp(432) : see reference to class template instantiation 'boost::unordered_detail::hash_buffered_functions' being compiled 1> with 1> [ 1> H=boost::hash, 1> P=std::equal_to 1> ] 1> d:\uni\ict312\labproject\labproject\inc\boost\unordered\detail\fwd.hpp(572) : see reference to class template instantiation 'boost::unordered_detail::hash_table' being compiled 1> with 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) : see reference to class template instantiation 'boost::unordered_detail::hash_unique_table' being compiled 1> with 1> [ 1> T=boost::unordered_detail::map,std::equal_to,std::allocator>> 1> ] 1> d:\uni\ict312\labproject\labproject\inc\collisiondetector.h(15) : see reference to class template instantiation 'boost::unordered_map' being compiled 1> with 1> [ 1> K=unsigned int, 1> T=PhysicsObject 1> ]

+1  A: 

Do you mean, that you include Debug.h after all other #include lines, and still get compilation errors in the boost headers? This may happen when compiler tries to instantiate template class, only at this point template code is really compiled. The only way to prevent this is to return to original new operator in the code fragment which causes this error. There is no chance to compile boost stuff with redefined new operator.

Another way is to move code lines that are not compiled into separate .cpp file without new redefinition.

Alex Farber