Determining the Access Type of Class Member Variables
Will the following table best define the access type of the member variables of the class I'm creating (sorry if this table is hard to see, the same table shows http://www.cplusplus.com/doc/tutorial/inheritance/ )?
Access public protected private
members of the same class yes yes yes
members of derived classes yes yes no
not members yes no no
0
a source to share
4 answers
The table is correct if this is what you are asking for.
In words, you can always access the member variables of the class your method is in. If a member variable is defined in the parent class, you can only access it if the member variable is protected or public. If you are outside the class, you can only access public member variables.
There is no "best way" - these are rules reasonably presented.
+1
a source to share