Why defining private members below public members in C++?

Gulshan picture Gulshan · Apr 27, 2009 · Viewed 15.2k times · Source

In C++ sometimes in class definition public members are declared at first and privates later. But the variables or data members are normally private and used by the public methods. So, in this case variables are used but not even declared yet. Thus the code become difficult to understand. But I found renowned programmers, sites or books to declare the private members later. Does anybody knows what is the reason?

Answer

Dominic Rodger picture Dominic Rodger · Apr 27, 2009

I do things that way round since users of my class don't care about the private members, they're interested in the public API (i.e. how to use my class).

Also, in header files I'm generally just declaring member functions, rather than defining them, so I'm not accessing any private members anyway.