WHAT IS PRIVATE DATA?

Examine the file named INHERIT5.CPP where the data is allowed to use the private default. In this program, the data is not available for use in the derived classes, so the only way the data in the base class can be used is through use of messages to methods in the base class.

It seems a little silly to have to call methods in the base class to get to the data which is actually a part of the derived class, but that is the way C++ is defined to work. This would indicate to you that you should spend some time thinking about how any class you define will be used. If you think somebody may wish to inherit your class into a new class and expand it, you should make the data members protected so they can be easily used in the new class. Be sure to compile and execute this program.

Share
Tweet
Share
Pin