Explore BrainMass

Explore BrainMass

    A C++ example of classes and inheritance

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Write a C++ program that uses 7 classes following a tree inheritance structure.

    The base class must also have a virtual print() function that displays the class name.

    Randomly assign print functions in three other classes that display the class name.

    Create 7 pointers of the base class and have them point to all the classes.

    Use the pointers to call print functions of all classes.

    © BrainMass Inc. brainmass.com October 10, 2019, 12:50 am ad1c9bdddf

    Solution Preview

    We will start by creating an inheritance structure where each class has two subclasses. The diagram looks like following:

    B C
    / /
    D E F G

    The virtual ...

    Solution Summary

    This solution provides a simple example of class inheritance in C++. It also illustrates the difference between virtual and non-virtual overridden methods.