错误 C2661:“CObject::operator new":没有重载函数需要 4 个参数 [英] error C2661: 'CObject::operator new' : no overloaded function takes 4 arguments

查看:16
本文介绍了错误 C2661:“CObject::operator new":没有重载函数需要 4 个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的 mfc 程序中查找内存泄漏.通常我会执行以下操作:

I have a memory leak that I'm trying to hunt down in my mfc program. Typically I would do something like the following:

头文件

// Leak Detection
#if defined(WIN32) && defined(_DEBUG)
     #define _CRTDBG_MAP_ALLOC
     #include <stdlib.h>
     #include <crtdbg.h>
#endif

cpp 文件

// Leak detection
#if defined(WIN32) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
    #ifdef DEBUG_NEW 
        #undef DEBUG_NEW
    #endif
    #define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
    #define new DEBUG_NEW
#endif

这种技术适用于大多数文件,但是当我将它包含在某些文件(例如我的文档)中时,我收到错误:错误 C2661:'CObject::operator new':没有重载函数需要 4 个参数

This technique works well in most files, but when I include it in some files such as my document, I get the error: error C2661: 'CObject::operator new' : no overloaded function takes 4 arguments

这里有什么解决方案?我应该在某个地方#undef-ing 新事物吗?

What's the solution here? Should I be #undef-ing new somewhere or something?

谢谢!

推荐答案

我也使用与您相同的功能来进行泄漏检测.

I also use the same functionality as you for the purpose of leak detection.

假设您不再需要它来捕获内存泄漏,您可以注释掉或删除 DEBUG_NEW 定义块.或者,如果您仍然需要它,请保持原样并使用

Either you can comment out or delete the DEBUG_NEW definition block, assuming you don't need it any more for trapping memory leaks. Or if you still need it, leave it as it is and use

#ifdef _DEBUG
#undef new
    CMyOject* pMyObjectInst = new CMyObject();
#define new DBG_NEW
#endif  

因此,您在对象创建之前取消定义 new(请参阅错误列表中的行号)并在之后立即重新定义它,以便在此对象创建之后发生的任何内存泄漏仍然可以识别.

So, you undefine new just before object creation (see the line numbers in your Error List) and redefine it again immediately after, so that any memory leaks which occur after this object creation are still identifiable.

这篇关于错误 C2661:“CObject::operator new":没有重载函数需要 4 个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆