Reputation: 147
Why would one prefer to use a private copy constructor over deleting the copy constructor in C++?
E.g.:
class Entity
{
private:
Entity(const Entity ©) // <== private copy constructor
{
/* do copy stuff */
}
public:
/* more code here... */
}
As opposed to:
class Entity
{
public:
Entity(const Entity ©) = delete; // <== copy constructor deleted
/* more code here... */
}
Related questions that don't quite answer what I'm asking:
What's the use of the private copy constructor in c++
Deleted vs empty copy constructor
Upvotes: 2
Views: 817
Reputation: 44238
2 possible reasons:
you cannot use C++11 or later
you need objects of the class to be copyable by methods of the class or it's friends, but not by anything else
Upvotes: 3