template <void (*T)(Entity *), typename Caller>
class Updater
{
public:
Updater(Caller c):m_caller(c){}
void process(Entity * e)
{
(m_caller->*T)(e); //Is this right?
}
private:
Caller m_caller;
};
我明白我可以實例像
Foo f;
Updater<&Foo::Bar> updater(&f);
假設Foo
具有
void Foo::Bar(Entity *e);
但如果它有想要的方法,怎麼辦?像這樣
template <typename T>
void Bar(T t);
我該怎麼辦呢?喜歡這個:?
Foo f;
Updater<&Foo::Bar<Entity *>> updater(&f);
當我這樣做是我真正的代碼,我得到
invalid template argument for ..., expected compile-time constant expression
所以2個問題:
1,是(m_caller->*T)(e);
正確的?如果不是,我叫它怎麼叫?
2,我該如何實例化它?
確定你在Updater <&Foo :: Bar中沒有空格>>更新器(&f);? –
Steed
2012-04-14 13:14:20
@它被稱爲「直角括號」 www2.research.att.c om /〜bs/C++ 0xFAQ.html#括號 – relaxxx 2012-04-14 13:18:15
我不認爲'Updater <&Foo::Bar>'是正確的,&Foo :: Bar是指向成員函數的指針,但是你的模板參數是指向函數的指針,它們不是相同的類型。 – Cosyn 2012-04-14 13:42:14