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

发布于 2024-12-09 19:09:18 字数 1387 浏览 0 评论 0原文

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

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 进行编译有效。

Hello I have upgraded my Xcode to version 4.2 and clang++ to version:

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

When try to compile the following code with 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;
};

I get the following error:

./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.

Compiling without -std=c++0x works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

涙—继续流 2024-12-16 19:09:18

对我来说这看起来像是一个叮叮当当的错误。我正在使用较新的 clang 版本,该版本没有此行为。您可以尝试为 ilpConstraint 提供显式复制构造函数作为临时解决方法。

This looks like a clang bug to me. I'm working with a later clang version which does not have this behavior. You might try giving ilpConstraint an explicit copy constructor as a temporary workaround.

谜兔 2024-12-16 19:09:18

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

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

With C++0x support the boost smart pointers define move constructors. This however disables implicit copying by the automatically generated copy constructor and assignment operator.

There is a patch for boost's smart pointers which refits the copy constructors and the assignment operators if the support for C++0x is detected.
It can be found here: https://svn.boost.org/trac/boost/changeset/73202

遇到 2024-12-16 19:09:18

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

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;
}

I ran into the same problem, when one of the members of my class, didn't have a default constructor anymore.

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文