如何从派生类复制构造函数调用基类复制构造函数? [复制]

Posted

技术标签:

【中文标题】如何从派生类复制构造函数调用基类复制构造函数? [复制]【英文标题】:How to call base class copy constructor from a derived class copy constructor? [duplicate] 【发布时间】:2013-06-23 01:54:16 【问题描述】:

就像标题一样,如何从派生类复制构造函数调用基类复制构造函数?

【问题讨论】:

更重要的问题是你为什么要这样做? 【参考方案1】:

您可以在初始化列表中指定基础初始化:

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

【讨论】:

【参考方案2】:
Derived( Derived const& d )
: Base(d)
/* some member initialization */

  /* ... */

我错过了什么吗?

【讨论】:

以上是关于如何从派生类复制构造函数调用基类复制构造函数? [复制]的主要内容,如果未能解决你的问题,请参考以下文章