should i list private items before public items in a class?

should i list all the private members before public members when creating a class or does it really not matter?
It doesn't matter to the compiler (except if your members are data members and their constructors depend on each other), but most people list the publics first, since that's what the people who read your header are most interested in.
Last edited on
As a convention (not a requirement), list your public member first, then protected, then private. The class declarations usually have the following form:

1
2
3
4
5
6
7
8
9
class SomeClass : public BaseClass
{
     public:
         ...
     protected:
         ...
     private:
         ...
}
Last edited on
It doesnt matter really, your program will work, but like qmzh85 said, there is a convention!
:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef CLASS_H
#define CLASS_H


class Class
{
    public:
        Class();
        virtual ~Class();
    protected:
    private:
};

#endif // CLASS_H 
Last edited on
Topic archived. No new replies allowed.