c++ - Does inheritance imply a deep copy of memory? -
i have class foo , bar. foo has resource. when bar inherits foo have deep copy of memory? or have call constructor of foo bars default-constructor?
class foo { char *item; public: foo() : item(new char[5]) {} }; class bar : public foo {};
the derived class has:
all members of base class + additional members in derived class the order of calling of constructors defined, base class constructor called before derived constructor. depending on how use member initialization list, either default base class constructor or parameterized version gets called.
but it's base class constructor followed derived class constructor. not sure second q is.
and precise, please remove char * member , use std::string.
class foo { //char *item; ----------------> erroneous, difficult handle std::string item; ....
Comments
Post a Comment