Klaus
Klaus

Reputation: 25613

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

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);
}

Upvotes: 1

Views: 40

Answers (1)

3CxEZiVlQ
3CxEZiVlQ

Reputation: 38518

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

Upvotes: 2

Related Questions