Well it:
private: MyClass(const MyClass&) {} MyClass& operator=(const MyClass&) {}
Still technically allowing MyClass copied by members and friends. Of course, these types and functions are theoretically under your control, but the class can still be copied. At least with boost::noncopyable and = delete no one can copy the class.
I don’t understand why some people claim that it is easier to make the class not copied in C ++ 11.
It is not as "easier" as "more easily digestible."
Consider this:
class MyClass { private: MyClass(const MyClass&) {} MyClass& operator=(const MyClass&) {} };
If you are a C ++ programmer who has read the C ++ introductory text but is not very prone to idiomatic C ++ (i.e. many C ++ programmers), this is ... confusing. It declares copy constructors and copy assignment operators, but they are empty. So why announce them at all? Yes, they are private , but this only raises more questions: why make them private?
To understand why this prevents copying, you must understand that by declaring them confidential, you do so so that no members / friends can copy it. This is not immediately clear to beginners. This is also an error message that they will receive when they try to copy it.
Now compare it with the C ++ 11 version:
class MyClass { public: MyClass(const MyClass&) = delete; MyClass& operator=(const MyClass&) = delete; };
What does it take to understand that this class cannot be copied? No more than understanding what the syntax = delete means. Any book explaining C ++ 11 syntax rules will tell you exactly what it does. The effect of this code is obvious to an inexperienced C ++ user.
What is good about this idiom is that it becomes an idiom, because it is the clearest, most obvious way of saying exactly what you mean.
Even boost::noncopyable requires a little thought. Yes, it is called “non-copyable,” so it’s self-documenting. But if you have never seen this, this raises questions. Why are you extracting from something that cannot be copied? Why do error messages talk about boost::noncopyable copy constructor? Etc. Again, understanding an idiom requires more mental effort.