C++11 constructor inheritance and constructors with no parameters

前端 未结 2 646
故里飘歌
故里飘歌 2020-12-20 16:33

In this piece of code, why is A\'s constructor with no parameters not inherited? Is there a special rule that prevents inheriting constructors with no parameters?

         


        
2条回答
  •  清歌不尽
    2020-12-20 17:06

    The relevant information is in 12.9 [class.inhctor] paragraph 3 (the highlighting is added):

    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. [...]

    That is, default constructor are not inherited unless they have a [defaulted] argument. If they have a default argument they are inherited but without the defaulted argument as is pointed out by a node on the same paragraph:

    Note: Default arguments are not inherited. [...]

    Basically, that says that default constructors are not inherited.

提交回复
热议问题