Default copy constructor and complex inheritance hierarchy

If we assume that we have this class hierarchy: A <-B <-C. I have the following questions:

1) If I implement copy constructor in B, should I call copy constructor A in implementation B?

2) Will the default copy constructor from C call the copy constructor that I implemented in B?

+4
source share
1 answer
  • Not necessarily, but it is good practice. It will not be called automatically. You can also call another constructor (or not, in which case the default constructor is called) and do what you want, although it is idiomatic to call the base copy constructor.

  • Yes it will.

+4
source

Source: https://habr.com/ru/post/1386872/


All Articles