With explicitly deleted member functions in C++11, is it still worthwhile to inherit from a noncopyable base class?

Well, this: private: MyClass(const MyClass&) {} MyClass& operator=(const MyClass&) {} Still technically allows MyClass to be copied by members and friends. Sure, those types and functions are theoretically under your control, but the class is still copyable. At least with boost::noncopyable and = delete, nobody can copy the class. I don’t get why some people … Read more

How do I make this C++ object non-copyable?

class Foo { private: Foo(); Foo( const Foo& ); // non construction-copyable Foo& operator=( const Foo& ); // non copyable public: static Foo* create(); } If you’re using boost, you can also inherit from noncopyable : http://www.boost.org/doc/libs/1_41_0/boost/noncopyable.hpp EDIT: C++11 version if you have a compiler supporting this feature: class Foo { private: Foo(); public: Foo( … Read more

What are the advantages of boost::noncopyable

I see no documentation benefit: #include <boost/noncopyable.hpp> struct A : private boost::noncopyable { }; vs: struct A { A(const A&) = delete; A& operator=(const A&) = delete; }; When you add move-only types, I even see the documentation as misleading. The following two examples are not copyable, though they are movable: #include <boost/noncopyable.hpp> struct A … Read more