0

Compiler: TDM-GCC 5.1.0 (SJLJ Unwinding)

I'm having an issue passing variable number of type arguments to a static variadic template method call inside of a template function. I've tried every syntax variation, but it won't compile, so I can only assume I'm doing this wrong.

Here's the setup:

#include <iostream>

template <class T>
struct Foo
{
    template <class...>
    static void test()
    {
        std::cout << "Foo<T>::test<...>() called.";
    }
};


template <class T, class... Args>
void bar()
{
    Foo<T>::test<Args...>();  //error happens here
}

int main()
{
    bar<int, int>();
}

This gives the compiler error: expected primary-expression before '...' token.

I thought pack expansions looked like Args..., but that doesn't seems to work here.

Any help is appreciated.

Paul Rich
  • 209
  • 2
  • 10
  • 2
    You'll probably find this question informative: ["Where and why do I have to put the `template` and `typename` keywords?"](https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – WhozCraig Nov 04 '16 at 16:56

1 Answers1

1

You need to tell the parser that dependant test is a template:

template <class T, class... Args>
void bar()
{
    Foo<T>::template test<Args...>();  //error happens here
            ^^^^^^^^^
}

demo

krzaq
  • 16,240
  • 4
  • 46
  • 61