Is an Abstract Class the same thing as a Base Class?
I occasionally see the term Base Class, but when I look up what it means, I tend to see "Abstract Class" thrown around.
Are they just two words that mean basically the same thing?
This is a typical base class Polygon:
class Polygon {
protected:
int width, height;
public:
void set_values (int a, int b)
{ width=a; height=b; }
virtual int area ()
{ return 0; }
};
class Rectangle: public Polygon {
public:
int area ()
{ return width * height; }
};
class Triangle: public Polygon {
public:
int area ()
{ return (width * height / 2); }
};
Abstract base classes are something very similar to the Polygon class in the previous example. They are classes that can only be used as base classes (you cannot instantiate them), and thus are allowed to have virtual member functions without definition (known as pure virtual functions). The syntax is to replace their definition by =0 (and equal sign and a zero):
An abstract base Polygon class could look like this:
// abstract class CPolygon
class Polygon {
protected:
int width, height;
public:
void set_values (int a, int b)
{ width=a; height=b; }
virtual int area () =0;
};