class Shape {
protected:
int width, height;
public:
Shape( int a = 0, int b = 0) {
width = a;
height = b;
}
int area() {
cout << "Parent class area :" <<endl;
return 0;
}
};
class Rectangle: public Shape {
public:
Rectangle( int a = 0, int b = 0):Shape(a, b) { }
int area () {
cout << "Rectangle class area :" <<endl;
return (width * height);
}
};
Rectangle is derived from Shape. So any time you construct a Rectangle object, the program must first construct the Shape base object. Shape(a,b) {} tells the compiler to construct the base Shape object by calling Shape(a,b) on it. Once that's done, it will run what's inside the braces of the Rectangle object's constructor. In this case, { } means that there is no code to run.