pradeexsu
pradeexsu

Reputation: 1145

Is there any special meaning of writing private at the end of class in C++?

I am learning WxWidgets and I found this code in Cross-Platform GUI Programming with wxWidgets on page no. 30:

class MyFrame : public wxFrame
{
  public:
    // Constructor
    MyFrame(const wxString& title);
    // Event handlers
    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
  private:
};

Is there any special meaning of writing private at the end of a C++ class?

Upvotes: 1

Views: 205

Answers (4)

schorsch312
schorsch312

Reputation: 5694

No there is no special meaning. It expresses explicitly, that the class contains no private data or methods. You may consider using a struct instead of the class and skip the public: and private: statement.

Upvotes: 3

kdcode
kdcode

Reputation: 522

The private keyword in the code you posted in its current form serves no purpose at all. Even if the class had some private member writing private is optional as class members are private unless stated otherwise.

But, it is a good practice to put public part of the class on top. The rational is that someone viewing the header files is most likely curios about its public interface. Therefore putting publics on top is useful for readability.

In this particular case, the writer of the class put private there to remind future authors of this file to follow the aforementioned style, e.g. public first.

Upvotes: 3

JunBeom Kim
JunBeom Kim

Reputation: 19

no meaning. that just used for explicit expression.

Upvotes: 1

I believe it is just a matter of coding style or coding discipline, or habits.

Read this C++ reference and some C++ standard draft, e.g. n3337.

In your particular case, the private: is useless, since nothing appears inside the class after it.

But future contributors to wxWdigets know at once where should a future private member function be added.

Upvotes: 5

Related Questions