Why does the implicit copy constructor calls the base class copy constructor and the defined copy constructor doesn't?

前端 未结 3 2001
醉话见心
醉话见心 2020-12-12 17:25

Consider a class hierarchy where A is the base class and B derives from A.

If the copy constructor is not defined in B

3条回答
  •  感动是毒
    2020-12-12 18:00

    The simple (possibly trite) answer is because you didn't tell it to. Since you are writing the derived copy constructor, you completely control how it behaves. Failure to specify a call to the base and the compiler generates code to initialize the base class by calling the base classes default constructor.

提交回复
热议问题