开发者

Compiling error when overwriting "new"

开发者 https://www.devze.com 2023-03-03 22:03 出处:网络
I\'m trying to control mem leaks in my code. In my general header file I\'ve added this code: // You may need to locate mem leaks

I'm trying to control mem leaks in my code. In my general header file I've added this code:

    // 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

If I add this code, I get this compilation error:

1>c:\archivos de programa\microsoft visual studio 9.0\vc\include\xlocmon(283) : error C2061: syntax error : identifier '_DebugHeapTag_func'
1>        c:\archivos de programa\microsoft visual studio 9.0\vc\include\xlocmon(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 programa\microsoft visual studio 9.0\vc\include\xlocmon(908) : see reference to class template instantiation 'std::moneypunct<_Elem,_Intl>' being compiled
1>        with
1>        [
1>            _Elem=char,
1>            _Intl=true
1>        ]

In addition, In my source code I have this inclusion:

#include "core/zelCoreLib.h"
#include <boost/shared_ptr.hpp>

Where mem leak control code is into zelCoreLib.h

To those not have VC9.0 this is the code that "fails"

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);
        }

It seems to be part of string and locale facilities. Also, as an additional information, I use Lua and LuaBind libs

Any help will be welcome


You have a #define new. new is a keyword, and #defineing it results in undefined behavior if you include any header in the standard library. The standard library almost certainly uses placement new in some places, for example, and your macro will cause any use of placement new to break. It will also cause any class specific new to break—and the library might use these as well. You cannot redefine keywords and expect anything to work.

0

精彩评论

暂无评论...
验证码 换一张
取 消