[ fromfile: multiple-inheritance.xml id: multinsimpleex ]
One class is concerned with shape and location, whereas the other is concerned with color and visibility characteristics.
A Window
must be a Rectangle
and a ScreenRegion
.
They are defined in Example 22.7.
Example 22.7. src/multinheritance/window.h
[ . . . . ] class Rectangle { public: Rectangle( Const Point& ul, int length, int width); Rectangle( const Rectangle& r) ; void move (const Point &newpoint); private: Point m_UpperLeft; int m_Length, m_Width; }; class ScreenRegion { public: ScreenRegion( Color c=White); ScreenRegion (const ScreenRegion& sr); virtual color Fill( Color newColor) ; void show(); void hide(); private: Color m_Color; // other members... }; class Window: public Rectangle, public ScreenRegion { public: Window( const Point& ul, int len, int wid, Color c) : Rectangle(ul, len, wid), ScreenRegion(c) {} Window( const Rectangle& rect, const ScreenRegion& sr) : Rectangle(rect), ScreenRegion(sr) {} // Other useful member functions ... };
Example 22.8. src/multinheritance/window.cpp
Default Initialization or assignment proceeds member-by-member in the order that data members are declared in the class definition:
base classes
derived class members.
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |