There is no limit to the number of access specifiers (private, protected, and public) a class can have. When large classes are declared, it is useful to repeat the access specifier frequently to improve readability. You can also group class members logically. For example, you can declare all constructors under one access specifier, the destructor with its own access specifier, and similarly–overloaded operators, ordinary methods, etc.:
class DatabaseTable { // a large class representing a relational database tableprivate: //data members int rows; string tableName; int fieldsPerRecord; //some useful comments appear hereprivate: //access specifier repeated to improve readability Date created; //page break hereprivate: Date lastSortedpublic: //constructors DatabaseTable(const DatabaseTable& other); //copy constructor DatabaseTable(); //default constructorpublic: //assignment operator DatabaseTable& operatot = (const DatabaseTable&);public: //destructor ~DatabaseTable();public: //_ rest of member functions};
In fact, you can explicitly declare every class member with its own access specifier (like in Java). As opposed to common belief, repetition of access specifiers does not impose any performance overhead so you can use as many specifiers as you like.