clang++ error message when using C++0x: call to deleted constructor of
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 followin开发者_开发知识库g 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.
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.
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
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;
}
精彩评论