c++ - Do default constructors need to call base class default constructors? -
was reading this answer , surprised me, suggestion must always call base class constructor in derived class constructor. if working default constructors, consider:
class bar : public foo { private: int y; public: bar() : foo(), y(0) { } ...
is call foo()
necessary here?
you not need explicitly call base class constructor in constructor, in case compiler implicitly calls default constructor, or compile-time error, if none callable.
same applies members non-pod.
an alternative member initialiser list only consisting of delegation constructor of class, creating delegating constructor.
Comments
Post a Comment