<<Effective C++ >>, Scott Meyers
Item 36: Differentiate between inheritance of interface and inheritance of implementation.
The notion of (public) inheritance turns out to be composed of two separable parts: inheritance of function interfaces and
inheritance of function implementations.
As a class designer, we sometimes want our derived classes <Goal1>to inherit only the interface of a member function; sometimes we want derived classes <Goal2>to inherit both the interface and the implementation of a member function and allow them to override the impementation inherited;sometimes we want derived classes <Goal3>to inherit both the interface and the implementation of a member function without allowing them to override anything.
Here goes the example class hierarchy for representing geometric shapes in graphics application:
Shape is an abstract class; its pure virtual function draw make it as such. As a result, clients cannot create instances of Shape class, only of the classes derived from it.
To achieve <Goal1>
Consider the pure virtual function draw. The two most salient features of pure virtual functions are that they must be redeclared by any concrete class that inherits them, and they typically have no definition in abstract classes.The purpose of declaring a pure virtual function is to have derived classes inherit a function interface only. By declaring draw as a pure virtual fuction, we just tell the designers of subclasses, “You must provide a draw function, but I have no idea how you're going to implement it.“
To achieve <Goal2>
to be continued
To achieve <Goal3>
to be continued
The above writing is almost a copy from the book, just for my English spelling and C++ learning.
Wondering how things work out about the new function overriding features like explicit overriding, renamed overriding and multiple overriding in C++/CLI. Will it bring new applications on inheritance model above? Or simply have no connections here.
About Indigo
a mark for further reading.
Array
a mark for further reading.
Retangular array and Jagged array(array of array?).