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

Why user-defined move-constructor disables the implicit copy-constructor?

I’ve upvoted ildjarn’s answer because I found it both accurate and humorous. 🙂 I’m providing an alternate answer because I’m assuming because of the title of the question that the OP might want to know why the standard says so. background C++ has implicitly generated copy members because if it didn’t, it would’ve been still-born … Read more

C++ Compiler Error C2280 “attempting to reference a deleted function” in Visual Studio 2013 and 2015

From [class.copy]/7, emphasis mine: If the class definition does not explicitly declare a copy constructor, a non-explicit one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; otherwise, it is defined as defaulted (8.4). The latter case is deprecated if … Read more

The copy constructor and assignment operator

No, they are different operators. The copy constructor is for creating a new object. It copies an existing object to a newly constructed object.The copy constructor is used to initialize a new instance from an old instance. It is not necessarily called when passing variables by value into functions or as return values out of … Read more

Why must the copy assignment operator return a reference/const reference?

Strictly speaking, the result of a copy assignment operator doesn’t need to return a reference, though to mimic the default behavior the C++ compiler uses, it should return a non-const reference to the object that is assigned to (an implicitly generated copy assignment operator will return a non-const reference – C++03: 12.8/10). I’ve seen a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)