为什么人们宁愿使用私有(private)复制构造函数而不是删除 C++ 中的复制构造函数?
例如:
class Entity
{
private:
Entity(const Entity ©) // <== private copy constructor
{
/* do copy stuff */
}
public:
/* more code here... */
}
相对于:
class Entity
{
public:
Entity(const Entity ©) = delete; // <== copy constructor deleted
/* more code here... */
}
无法完全回答我的问题的相关问题:
最佳答案
2个可能的原因:
您不能使用 C++11 或更高版本
您需要类的对象可以被类或其友元的方法复制,但不能被其他任何东西复制
关于c++ - 为什么在 C++ 中使用私有(private)复制构造函数与删除的复制构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53127611/