使用C ++时的clang ++错误消息0x:调用已删除的构造函数

时间:2011-10-13 13:03:24

标签: c++ c++11 clang

您好我已将Xcode升级到版本4.2并将++升级到版本:

Apple clang version 3.0 (tags/Apple/clang-211.10.1) (based on LLVM 3.0svn) 
Target: x86_64-apple-darwin11.2.0
Thread model: posix

尝试使用clang -std = c ++ 0x

编译以下代码时
#include <memory>
#include <limits>
#include <boost/shared_ptr.hpp>


class ilpConstraintImpl {
public:
    virtual ~ilpConstraintImpl() {}
};


class ilpConstraint {
public:
    ilpConstraint(ilpConstraintImpl* implptr):impl(implptr) { }
public:
    boost::shared_ptr<ilpConstraintImpl> impl;
};

class ilpExprImpl {
public:
    virtual ilpConstraint operator<= (const double rs)=0;
    virtual ~ilpExprImpl() {}
};



class ilpExpr {
 public:
    virtual ~ilpExpr() {};
    ilpConstraint operator<= (const double rs) { return impl->operator<=(rs); }
    ilpExpr(ilpExprImpl* implptr):impl(implptr) { }
    boost::shared_ptr<ilpExprImpl> impl;
};

我收到以下错误:

./test.h:46:54: error: call to deleted constructor of 'ilpConstraint'
    ilpConstraint operator<= (const double rs) { return impl->operator<=(rs); }
                                                        ^~~~~~~~~~~~~~~~~~~~
./test.h:28:7: note: function has been explicitly marked deleted here
class ilpConstraint {
      ^
1 error generated.

在没有-std = c ++ 0x的情况下进行编译。

3 个答案:

答案 0 :(得分:6)

这对我来说就像一个铿锵的错误。我正在使用后来没有这种行为的clang版本。您可以尝试将ilpConstraint显式复制构造函数作为临时解决方法。

答案 1 :(得分:3)

使用C ++ 0x支持,boost智能指针定义移动构造函数。但是,这会禁用自动生成的复制构造函数和赋值运算符的隐式复制。

有一个boost的智能指针补丁,如果检测到对C ++ 0x的支持,它会重写复制构造函数和赋值运算符。 可在此处找到:https://svn.boost.org/trac/boost/changeset/73202

答案 2 :(得分:1)

当我的班级成员之一没有默认构造函数时,我遇到了同样的问题。

struct OrderContact {
    std::string name;
    std::string phone;
    OrderContact() {}  // error without this constructor
    OrderContact(std::string contactName, std::string contactPhone) : name(contactName), phone(contactPhone) {
    }
};

class Order {
public:
    OrderContact contact;
}