【问题标题】:Error 35 error C2661: 'operator new' : no overloaded function takes 2 arguments错误 35 错误 C2661:'operator new':没有重载函数需要 2 个参数
【发布时间】:2014-12-11 12:12:18
【问题描述】:

我不是一个熟练的 C++ 程序员,我在一个 Visual Studio 解决方案中得到了一个非常大的项目(实际上是 24 个)。

我几乎在所有项目中都遇到了这个错误,我不知道如何解决它。

当我双击错误时,它会将我带到这个地方:

for( int i = 0; i < nNewSize; i++ )
#pragma push_macro("new")
#undef new
        ::new((void*)(m_pData+i))TYPE;
#pragma pop_macro("new")

构建顺序输出给了我这个:

c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\afxtempl.h(403): error C2661: 'operator new' : no overloaded function takes 2 arguments
19>          c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\afxtempl.h(368) : while compiling class template member function 'void CArray<TYPE,ARG_TYPE>::SetSize(INT_PTR,INT_PTR)'
19>          with
19>          [
19>              TYPE=D2D1_GRADIENT_STOP,
19>              ARG_TYPE=D2D1_GRADIENT_STOP
19>          ]
19>          c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\afxtempl.h(643) : see reference to function template instantiation 'void CArray<TYPE,ARG_TYPE>::SetSize(INT_PTR,INT_PTR)' being compiled
19>          with
19>          [
19>              TYPE=D2D1_GRADIENT_STOP,
19>              ARG_TYPE=D2D1_GRADIENT_STOP
19>          ]
19>          c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\afxtempl.h(355) : while compiling class template member function 'CArray<TYPE,ARG_TYPE>::~CArray(void)'
19>          with
19>          [
19>              TYPE=D2D1_GRADIENT_STOP,
19>              ARG_TYPE=D2D1_GRADIENT_STOP
19>          ]
19>          c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\afxrendertarget.h(1028) : see reference to class template instantiation 'CArray<TYPE,ARG_TYPE>' being compiled
19>          with
19>          [
19>              TYPE=D2D1_GRADIENT_STOP,
19>              ARG_TYPE=D2D1_GRADIENT_STOP
19>          ]

afxrendertarget.h 在 1028 处有这一行

CArray<D2D1_GRADIENT_STOP, D2D1_GRADIENT_STOP>      m_arGradientStops;

我试图在我的脚本中注释以下行:

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

但它没有效果。

请帮帮我!

【问题讨论】:

  • 我的建议是立即逃跑。这个项目只会带来痛苦。
  • 是的,我知道。这是我工作的第二周,我开始感到非常沮丧。我已经解决了很多错误,现在我就在这一点上。
  • 我想知道什么样的组织会为没有经验的 C++ 程序员提供包含 24 个项目的解决方案。这么多代码,不懂C++就无法维护C++。

标签: c++ operator-overloading new-operator


【解决方案1】:

你展示的一小段代码太可怕了:如果new被定义为 一个宏,你有未定义的行为,至少如果你包含任何 标准标题。

不过,我想编译器抱怨的那一行是什么 称为安置新。要使用它,您必须包含标题 &lt;new&gt;。 (如果new 已被定义为宏,这将不起作用。 找到这个定义出现的地方,然后去掉它。)

【讨论】:

  • 谢谢!有效。我之前尝试过评论,但我从未包含
猜你喜欢
  • 2012-06-12
  • 1970-01-01
  • 1970-01-01
  • 2017-05-01
  • 2018-12-30
  • 1970-01-01
  • 1970-01-01
  • 2021-07-05
  • 1970-01-01
相关资源
最近更新 更多