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

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

【问题讨论】:

  • 更重要的问题是你为什么要这样做?

标签: c++ inheritance constructor copy-constructor


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:
    Derived( Derived const& d )
    : Base(d)
    /* some member initialization */
    {
      /* ... */
    }
    

    我错过了什么吗?

    【讨论】:

      猜你喜欢
      • 2019-08-07
      • 1970-01-01
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      • 2011-03-11
      • 1970-01-01
      • 1970-01-01
      • 2012-02-28
      相关资源
      最近更新 更多