The second question would be how do I call the Base class's function without explicitly specifying the base class name (i.e. a dynamic reference, something to emulate "super")?
Since you have "generic stuff" to do, the solution is to provide a protected virtual function that subclasses override if they want to do more than the "generic stuff", and then have the base class provide the "generic stuff" in a non-virtual function, e.g.,
Code:
class Polygon
{
public:
void draw()
{
// do generic stuff
// ...
// do specific stuff, if any.
drawMore();
}
virtual ~Polygon() {}
protected:
long double x;
long double y;
virtual void drawMore() = 0;
};
class Rectangle : public Polygon
{
protected:
virtual void drawMore()
{
// do specific stuff
// ...
}
protected:
long double width;
long double height;
};