我正在嘗試爲類模板創建某種回調。代碼是這樣的:覆蓋模板類功能
template <typename t>
class Foo {
void add(T *t) {
prinf('do some template stuff');
on_added(t);
}
void on_added(T *t) { }
}
struct aaa {}
class Bar : Foo<aaa> {
void on_added(aaa *object) {
printf("on added called on Bar");
}
}
酒吧on_added函數永遠不會被調用。添加模板子類可以選擇覆蓋的回調的最佳方法是什麼?謝謝
難道你不是在基類的void on_added(...)前面缺少虛擬嗎? – 2010-08-15 17:51:09
是的,它的工作原理,謝謝。 Newb錯誤,我應該刪除這個問題嗎? – sharvey 2010-08-15 17:54:00