课堂上有几个"私人"声明

A F*_*ich 5 c++ class declaration

我正在浏览一些开源代码并找到类似这样的类声明:

class Foo{
    private:
        // declarations
    private:
        // declarations
    private:
        // declarations
    public:
        // declarations
};
Run Code Online (Sandbox Code Playgroud)

有没有时间你想做这样的事情,除了在有长的声明清单时提醒你成员的隐私?

Mat*_*son 4

这对于这种类型的场景特别有用:

class SomeClass
{
   // COnstructors etc.
   public:
      SomeClass();
      SomeClass(const SomeClass& other);
      ~SomeClass();
      SomeClass operator=(const SomeClass& other);
      SomeClass(const OtherClass& other); 

   // Internal use functions. 
   private:
       int SomePrivateFunc();
       int OtherPrivateFunc();

   // Functions that "do stuff" with this class. 
   public:
       int SomeFunc();
       int OtherFunc();

   // Private member variables. 
   private:
       int x, y; 

   // Public member variables.
   public:
       int value; 
}
Run Code Online (Sandbox Code Playgroud)

(像这样的评论// Constructurs etc.只是为了表明这是“这些东西属于在一起”的一部分)