[問題] function pointer中使用template未定型別
問題(Question):
各位好,請問大家
function pointer中,若想要用template變數的話(型別未定),要怎麼樣使用呢?
例如我先定義FunctionTypeA,代表的是 輸出為void、輸入為一個int參數 的函數型別
typedef void (*FunctionTypeA) (int& anItem);
這樣的話我往後可以把這種型別的函數餵給其他函數去呼叫
例如void function(FunctionTypeA func) { ... }
但是今天我FunctionTypeA的的某些型別未定,例如上面的參數int,不確定要用int
我想要把int換成template <class T>中的T
如果
typedef void (*FunctionTypeA) (T& anItem); 這樣去寫
g++會出現
[Error] typedef 'FunctionTypeA' is initialized (use decltype instead)
[Error] 'T' was not declared in this scope
[Error] 'anItem' was not declared in this scope
的錯誤
如果是
template <class T>
typedef void (*FunctionTypeA) (T& anItem);
g++會出現
[Error] template declaration of 'typedef'
請問大家知道要如何修正嗎?
萬分感謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.136.225.126
推
12/09 22:21, , 1F
12/09 22:21, 1F
→
12/09 22:21, , 2F
12/09 22:21, 2F
→
12/09 22:21, , 3F
12/09 22:21, 3F
→
12/09 22:37, , 4F
12/09 22:37, 4F
→
12/09 22:43, , 5F
12/09 22:43, 5F
→
12/09 22:44, , 6F
12/09 22:44, 6F