reddish
reddish

Reputation: 1400

How can I use a variadic template to define a type inside the class?

I want to be able to typedef a type f inside a class to be an std::function that takes a number of parameters, the number and type of which depends on the template parameter of the class, like this:

#include <functional>

template <typename ... Args>
class SomeClass
{
    typedef std::function<void(Args)> f;
};

However, this does not work. g++ with -std=c++0x bails out with "error: parameter packs not expanded with ‘...’.

I am trying to wrap my head around a bunch of new C++11 features, and it is quite possible that I am missing a very obvious solution. Any help would be appreciated.

Upvotes: 0

Views: 131

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409176

The error message tells you exactly what wrong and how you can solve it... Add the ellipsis:

typedef std::function<void(Args...)> f;

Upvotes: 2

Related Questions