我有一個TaskWrapper:作爲模板參數
template <typename T, T (*F)(T)>
struct TaskWrapper {
static inline T run(T clock) {
return F(clock);
}
};
使用它,我必須指定T模板參數:
uint16_t task1(uint16_t clock) { return clock + 1; }
typedef tasks::TaskWrapper<uint16_t, task1> Task;
我想簡單地寫:
typedef tasks::TaskWrapper<task1> Task;
並讓編譯器確定返回和參數類型是uint16_t。
注:
的TaskWrapper明顯簡化,在現實中還有其它幾個參數,這些參數typedef的過程中傳遞。
包裹的功能只能是:
uint8_t task(uint8_t clock);
uint16_t task(uint16_t clock); // or
uint32_t task(uint32_t clock);
的TaskWrapper作爲模板參數到另一個類,通過它會在某個時候調用任務::運行(...);
C++ 11會很好。
什麼'模板使用任務=任務:: TaskWrapper ;'然後把它作爲任務''。 –
Zereges