using delcaration to inherit constructors from all base classes given by variadic template arg

Issue

If I derive from one or more classes I can inherit the constructors with the using declaration.

Example:

struct A
{
    A(int){}
    A(){}
};

struct B
{
    B(char){}
    B(){}
};

struct All: public A,public B
{
    using A::A;
    using B::B;
};

If I want do the same within a template class, where the base classes are given by a variadic template parameter, how can I use the using declaration?

Example ( The same as above, but using a template class to inherit )

template < typename ... P>
struct All2: public P...
{
    using P...::P...; ??? is there a syntax available to "use" the constructors from all base classes?
};

And the main can be something like:

int main()
{
    All all1(1);
    All2<A,B> all2(2);
}

Solution

template < typename ... P>
struct All2: public P...
{
    using P::P...;
};

Answered By – 273K

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.