【问题标题】:Error operator new[] : function does not take 1 arguments错误运算符 new[]:函数不接受 1 个参数
【发布时间】:2010-09-10 10:04:10
【问题描述】:

我有重载运算符new 的代码。下面的代码在 Linux (gcc4x) 下运行良好,但在 Windows (Visual C++ 2008 Express Edition) 下运行良好

Visual Studio 2008 Express Edition 下的代码报告

error C2660: operator new[] : function does not take 1 arguments

class dummy{};
void* operator new[] (size_t size, dummy gcp)
{
  return ::operator new[](size);   //error
}

int main()
{
    dummy dummyobj;
    dummy* ptr = new (dummyobj) dummy[5];
    return 0;
}

【问题讨论】:

  • 什么是“dummy gcp”?
  • 如果您在代码中编译器抱怨的行添加注释通常会很有帮助。这在人们不熟悉编译器的特定错误格式的情况下会有所帮助,因为它有助于推断编译器试图告诉你的内容。
  • 顺便说一句,这段代码没有意义。您正在实施展示位置 new,但让它表现得像正常的 new
  • @David 不,他没有实施新的展示位置,他只是将一个额外的参数放入新的,让用户能够使用稍微修改的新的。这就是 new (std::nothrow) 的实现方式。
  • 实际上像这样的代码来自 OpenC++ ,我试图让我的项目在 Windows 下使用它。谢谢大家。

标签: c++ visual-c++-2008 new-operator


【解决方案1】:

您可能需要#include <new>

【讨论】:

    猜你喜欢
    • 2013-03-26
    • 1970-01-01
    • 2013-11-18
    • 1970-01-01
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    相关资源
    最近更新 更多