2

What's the syntax to typdef a parameter pack into a function pointer?

I want to be able to typedef a function pointer, but the compiler complains when I do something like this

template< class ...Args >
struct method { typedef typename void(*type)(void*, Args...); };

with a message along the lines of error: expected nested-name-specifier before 'void'

max66
  • 65,235
  • 10
  • 71
  • 111
Stefan Sullivan
  • 1,517
  • 2
  • 10
  • 9
  • See also: http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords – Sam Varshavchik Nov 29 '16 at 00:36
  • Shit, sorry guys. I misread an error from my compiler that said `error: need 'typename' before ...` but I put it there in the struct instead of the reference to the dependent type :/ – Stefan Sullivan Nov 29 '16 at 01:23

2 Answers2

2

It works fine without typename. http://coliru.stacked-crooked.com/a/64b3fbec9276dd70

You shouldn't use typename here because there is no nested-name-specifier.

Brian Bi
  • 111,498
  • 10
  • 176
  • 312
1

I suppose that you should remove typename from the typedef line

template <typename ... Args>
struct method
 { typedef void(*type)(void*, Args...); };

Another solution could be using using instead of typedef (IMHO is a little clearer)

template <typename ... Args>
struct method
 { using type = void(*)(void*, Args...); };
max66
  • 65,235
  • 10
  • 71
  • 111