Copy constructor is not inherited

后端 未结 3 852
感动是毒
感动是毒 2020-11-28 12:16

I\'ve got the following code:

class C {
public:
    C(int) {}
    C(const C&) {}
    C() {}
};  

class D : public C { 
public:
    using C::C;
};  

int         


        
3条回答
  •  一向
    一向 (楼主)
    2020-11-28 12:49

    Because the standard says so. [class.inhctor]/p3, emphasis mine:

    For each non-template constructor in the candidate set of inherited constructors other than a constructor having no parameters or a copy/move constructor having a single parameter, a constructor is implicitly declared with the same constructor characteristics unless there is a user-declared constructor with the same signature in the complete class where the using-declaration appears or the constructor would be a default, copy, or move constructor for that class.

提交回复
热议问题