Inherit and overload default constructor

前端 未结 1 1824
粉色の甜心
粉色の甜心 2020-12-10 19:09

I\'ve been searching for this and I\'m amazed I haven\'t found anything. Why can\'t I inherit a base class constructor using using declaration and add an overlo

相关标签:
1条回答
  • 2020-12-10 19:57

    The problem is that default-constructors are not inherited. From [class.inhctor]/p3:

    For each non-template constructor in the candidate set of inherited constructors [..], 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.

    You also have a user-declared constructor that suppresses the creation of an implicit default-constructor. Just add a defaulted one to make it work:

    B() = default;
    
    0 讨论(0)
提交回复
热议问题