3

How i can use "using" keyword in multiple inheritance when parameter pack is template parameter of base class?

Code below compiles just fine

struct A
{
 void foo(int) {}
};
struct B
{
 void foo(int) {}
};
template<typename ...Types>
struct C : public Types...
{
 using Types::foo...;
};
int main()
{
 C<A,B> c;
}

But if i use template instead of A and B - I've got compile error

template<typename T> 
struct TA {};
template<>
struct TA<int>
{ 
 void foo(int) {} 
};
template<>
struct TA<double>
{
 void foo(int) {}
};
template<typename ...Types>
struct TC : public TA<Types>...
{
 using TA<Types>::foo...; // ERROR C3520
};

Error:

error C3520: 'Types': parameter pack must be expanded in this context

How to rewrite second piece of code to get it work?

PS I tried this code with gcc and it's compiles without errors. But now I am using msvc...

asked Aug 19, 2019 at 17:21
2

1 Answer 1

1

Since it's a known MSVC bug, if you still want to make this work with MSVC you'll have to do it the (not very) hard way:

template <typename ...Types>
struct TC;
template <typename T>
struct TC<T> : TA<T>
{
 using TA<T>::foo;
};
template <typename T, typename ...Types>
struct TC<T, Types...> : public TC<T>, public TC<Types...>
{
 using TC<T>::foo;
 using TC<Types...>::foo;
};
answered Aug 19, 2019 at 17:43
Sign up to request clarification or add additional context in comments.

1 Comment

In fact, this is how things have to be done prior to C++17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.