Answer the question
In order to leave comments, you need to log in
C++ Constructors in inherited class?
If the base class has fields and a constructor that initializes them, then how to write a constructor for the inherited class? On msdn it is written that you need to specify all the parameters of the parent constructor, but this is not very convenient if the inherited class has completely different fields.
p.s. example from msdn doesn't compile
lass StorageBox : public Box {
public:
StorageBox(int width, int length, int height, const string label&) : Box(width, length, height) {
m_label = label;
}
private:
string m_label;
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question