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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -