错误 C2661:'CObject::operator new':没有重载函数需要 4 个参数
error C2661: 'CObject::operator new' : no overloaded function takes 4 arguments
我有一个内存泄漏,我试图在我的 mfc 程序中寻找它。通常我会做如下事情:
头文件
// 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::运算符新":没有重载函数需要 4 个参数
这里的解决方案是什么?我应该在某个地方或某事上 #undef 新事物吗?
谢谢!
我也使用与您相同的功能进行泄漏检测。
您可以注释掉或删除DEBUG_NEW定义块,假设您不再需要它来捕获内存泄漏。或者,如果您仍然需要它,请保持原样并使用
#ifdef _DEBUG
#undef new
CMyOject* pMyObjectInst = new CMyObject();
#define new DBG_NEW
#endif
因此,您在创建对象之前取消定义 new(请参阅错误列表中的行号),并在之后立即再次重新定义它,以便在此对象创建之后发生的任何内存泄漏仍然可以识别。
我有类似的问题,#define new DEBUG_NEW
放在文件中#include ...
语句之前.cpp。更改顺序解决了我的问题。
相关文章:
- 为什么使用SFINAE而不是函数重载
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- c++:可变模板和函数重载
- 在缺少函数重载时抛出异常,并带有 std::variant 而不是编译时错误
- 解决模板成员函数重载
- 为什么不允许成员函数和非成员函数之间的函数重载?
- 推断模板化函数中的函数重载
- C++复制函数重载导致"must be a nonstatic member function"错误
- 为什么 std::sort 找不到合适的(静态成员)函数重载?
- 可变参数泛型 lambda 和函数重载
- C++中的函数重载和继承
- 当有右值构造函数可用时,为什么从右值调用类引用构造函数重载?
- C/C++ 可变参数宏函数重载
- 将基类的成员函数重载到其他派生类C++
- C++ 函数重载匹配
- C++函数重载,具体步骤是什么
- C++:使用 param pack 显式调用函数重载
- 隐式生成的函数重载用于右值参数?
- 使用函数重载输入运算符
- 运算符重载函数上的函数重载