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

C++ template copy constructor on template class

A copy constructor is of the form X(X& ) or (X const&) and will be provided for you by the compiler if you didn’t declare one yourself (or a few other conditions which are not relevant here). You didn’t, so implicitly we have the following set of candidates: MyTemplateClass(const MyTemplateClass&); template <typename U> MyTemplateClass(const MyTemplateClass<U>&); … Read more