| Name | Last modified | Size | Description | |
|---|---|---|---|---|
| Parent Directory | - | |||
| main.cpp | 2013-11-12 00:40 | 1.8K | ||
| shape.h | 2013-11-12 00:22 | 2.1K | ||
| shape.cpp | 2013-11-12 00:25 | 3.6K | ||
| a.out | 2024-03-25 13:58 | 40K | ||
This example differs from the one in Shape2, in that the functions Print() and Area() have also been added to the base class Shape.
This makes the Print() and Area() functions in the Rectangle and Circle classes into function overrides.
This also means that we can now CALL Print() and Area() through a base class pointer (Shape*) or reference (Shape&) type.
The main program attempts the calls that were previously illegal in the last example. I've also added in a function that takes in a Shape by reference, and illustrates that we can pass Circles or Rectangles into this function (parent reference can refer to derived object).
HOWEVER, note the results of calling Print() or Area() through a base class pointer or reference, because in this example, those functions are NOT virtual.