C++ 伪私有方法

class Queue
{
private:
     Queue(const Queue & q) : qsize(0) {}    // preemptive definition 伪私有方法
     Queue & operator = (const Queue & q) { return *this; }  // preemptive definition 伪私有方法
    ...
};

将方法声明为伪私有方法的作用:

  • 避免了本来将自动生成的默认方法定义。
  • 因为这些方法是私有的,所以不能被广泛使用。
  • 在定义其对象不允许被复制的类时,这种方法也有用。
原文地址:https://www.cnblogs.com/suui90/p/13138009.html