Why would one prefer to use a private copy constructor over deleting the copy constructor in C++?
Eg:
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:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.