We had the code commented on 1-Aug-22 in response to N Hasan's question.
Quote:
Need to explain all the cases according to the errors
https://www.codeproject.com/Answers/5338717/Need-to-explain-all-the-cases-according-to-the-err#answer2
It's amazing how little personal effort goes into this question.
//Edit:
I can briefly touch on the basic context. However, it would be clearly necessary to read this in a basic book.
The Rectangle class inherits from the Shape class. The data is protected and is neither inherited nor is it directly modifiable via the Rectangle class. The class Shape has only one constructor, which has a float parameter. So the parameter is needed when creating an instance of the class.
class Shape {
public:
Shape(float a);
...
protected:
float w, h;
};
class Rectangle : public Shape
If you want to create an instance of the class Rectangle, the constructor of Shape is called, too. Now there are some questions.
1. where does the constructor of Shape get the parameter?
2. how are the protected parameters initialized?
In initialization lists, inherited properties cannot be accessed, therefore the properties are initialized by calling the corresponding constructor of the parent class.