我怎么知道" C2280 - 尝试引用已删除的功能"发生?

时间:2014-11-27 12:29:33

标签: c++ visual-c++ visual-studio-2013

我很难搞清楚代码中的哪一部分会导致标题中提到的错误。错误列表中的错误消息如下所示:

error C2280: 'Foo::Foo(const Foo &)' : attempting to reference a deleted function
    file: vector, line: 1100

编译器输出如下所示:

d:\visual studio 2013\vc\include\vector(1100): error C2280: 'Foo::Foo(const Foo &)'
 : attempting to reference a deleted function

e:\testproject\src\foo.h(22) : see declaration of 'Foo::Foo'
this diagnostic occurred in the compiler generated function
    'luabridge::luabridge::TypeListValues<luabridge::TypeList<P1,luabridge::None>>
    ::TypeListValues(const luabridge::TypeListValues<luabridge::TypeList<P1,luabridge::None>> &)'

with
[
    P1=Foo &
]

对我来说,此错误消息绝对没有说明错误发生的位置。我知道它是关于一个被删除的拷贝构造函数(foo.h中的第22行是删除的拷贝ctor),但就是这样。我想保留复制构造函数。

如何找出错误的确切发生?

1 个答案:

答案 0 :(得分:0)

如果没有看到更多的代码,很难准确,但也许您需要使用引用计数指针来代替对象本身。例如,请参阅this post