How to call base class copy constructor from a derived class copy constructor? [duplicate]

送分小仙女□ 提交于 2019-11-27 23:24:38

问题


This question already has an answer here:

  • Why aren't copy constructors “chained” like default constructors or destructors? 3 answers
  • Calling the base class constructor from the derived class constructor 5 answers

Just like in the title, how do you call a base class copy constructor from a derived class copy constructor?


回答1:


You can specify base initialization in the initialization list:

Derived:: Derived( const Derived& other ): Base( other )
{ /* ... */ }



回答2:


Derived( Derived const& d )
: Base(d)
/* some member initialization */
{
  /* ... */
}

Am I missing something?



来源:https://stackoverflow.com/questions/17311382/how-to-call-base-class-copy-constructor-from-a-derived-class-copy-constructor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!