我希望这能奏效
struct Parent
{
Parent ();
Parent (const Parent &);
};
struct Child : public Parent
{
using Parent::Parent;
};
Parent p;
Child c (p);
Run Code Online (Sandbox Code Playgroud)
Child继承了所有Parent的构造函数,对吧?
包括Parent::Parent(const Parent &)?
x.cpp:15:11: error: no matching function for call to ‘Child::Child(Parent&)’
Child c (p);
^
x.cpp:5:2: note: candidate: Parent::Parent(const Parent&)
Parent (const Parent &);
^~~~~~
x.cpp:10:16: note: inherited here
using Parent::Parent;
^~~~~~
x.cpp:10:16: note: an inherited constructor is not a candidate for initialization from an expression of the …Run Code Online (Sandbox Code Playgroud)