2016-11-29 57 views
1

將參數包打印到函數指針中的語法是什麼?如何用參數包參數typedef函數指針類型

我希望能夠到的typedef函數指針,但是當我做這樣的事情

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

沿的error: expected nested-name-specifier before 'void'

+0

參見:HTTP:/ /stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords –

+0

該死,對不起傢伙。我錯誤地從我的編譯器中看到錯誤:'error:need'typename'before ...',但我把它放在結構體中而不是引用依賴類型:/ –

回答

1

我想你應該從typedef

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

另一種解決方案可以使用using代替typedef刪除typename(恕我直言,是更清晰一點)

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