// multiple inheritance // In C++ it is possible that a class inherits members from more than one class. // This is done by simply separating the different base classes with commas in the // derived class declaration. For example, if we had a specific class to print // on screen (Output) and we wanted our classes Rectangle and Triangle to also // inherit its members in addition to those of Polygon we could write: #include using namespace std; class Polygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b;} }; class Output { public: void output (int i); }; void Output::output (int i) { cout << "The output is " << i << endl; } class Rectangle: public Polygon, public Output { public: int area () { return (width * height); } }; class Triangle: public Polygon, public Output { public: int area () { return (width * height / 2); } }; int main () { Rectangle rect; Triangle trgl; rect.set_values (4,5); trgl.set_values (4,5); rect.output (rect.area()); trgl.output (trgl.area()); getchar(); return 0; }