My question is simple. When do we need to have a default constructor? Please refer to the code below:
class Shape
{
int k;
public:
Shape(int n) : k(n) {}
~Shape() {}
};
class Rect : public Shape
{
int l;
public:
Rect(int n): l(n)
{} //error C2512: 'Shape' : no appropriate default constructor available
~Rect() {}
};
Why is the compiler not generating the zero argument default constructor implicitly in the class Rect?
As per my knowledge, if a class (Rect) is derived from another class (Shape) that has default constructor (either implicitly generated or explicitly provided), the default constructor should be generated by the compiler.