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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -