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

slo*_*low 15 c++ inheritance constructor copy-constructor

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

per*_*eal 29

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

Derived:: Derived( const Derived& other ): Base( other )
{ /* ... */ }
Run Code Online (Sandbox Code Playgroud)


小智 9

Derived( Derived const& d )
: Base(d)
/* some member initialization */
{
  /* ... */
}
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?