| Name | Last modified | Size | Description | |
|---|---|---|---|---|
| Parent Directory | - | |||
| main.cpp | 2013-11-12 00:40 | 1.6K | ||
| shape.h | 2013-11-12 00:37 | 2.2K | ||
| shape.cpp | 2013-11-12 00:37 | 3.5K | ||
| a.out | 2020-10-26 12:24 | 25K | ||
In this example, I've simply declared the Print() and Area() functions of the base class to be virtual. Print() is virtual, but still defined in the base class, because this version does some of the work. Area() is pure virtual, meaning that it is NOT defined in the base class (making Shape into an abstract class).
Note that the main.cpp test program is EXACTLY the same as in the Shape3 example. Note the difference between the outputs when these base functions are virtual (as in this example) versus when they are NOT virtual (Shape3), when we call the functions through a base class pointer or reference (Shape* or Shape& )