When you have a derived class, is there an simpler way to refer to a variable from a method other than:
BaseClass::variable
EDIT
As it so happens, I found a page that explained this issue using functions instead: Template-Derived-Classes Errors. Apparently it makes a difference when using templates classes.
If the base class member variable is protected or public than you can just refer to it by name in any member function of the derived class. If it is private to the base class the compiler will not let the derived class access it at all. Example:
There is also something to be said for keeping all member variables private, and providing getters and setters as needed.
Also, beware of ‘hiding’ data members:
This will create two variables named
a: one inBase, one inDerived, and it will likely lead to confusion and bugs.