Inheriting constructors

前端 未结 6 2083
无人及你
无人及你 2020-11-22 09:16

Why does this code:

class A
{
    public: 
        explicit A(int x) {}
};

class B: public A
{
};

int main(void)
{
    B *b = new B(5);
    delete b;
}
         


        
6条回答
  •  [愿得一人]
    2020-11-22 09:55

    How about using a template function to bind all constructors?

    template  Derived(T... t) : Base(t...) {}
    

提交回复
热议问题