1
什麼叫從一個類繼承與相同的方法名3個基類匹配方法的最佳方法相匹配的方法呢?我想打電話從一個單一的調用這些方法,不知道它甚至有可能呼叫從繼承類
template<typename T>
class fooBase()
{
void on1msTimer();
/* other methods that make usage of the template */
}
class foo
: public fooBase<uint8_t>
, public fooBase<uint16_t>
, public fooBase<float>
{
void onTimer()
{
// here i want to call the on1msTimer() method from each base class inherited
// but preferably without explicitly calling on1msTimer method for each base class
}
}
有沒有辦法做到這一點? 感謝
如果你想打電話給三個不同的功能,你*有*告訴編譯器你想調用哪三個函數。 –
一種選擇是所有基類從事件派發幾乎繼承,並註冊自己的實現施工過程中,調度員。然後,派生最多的類可以通過調度器調用函數列表。 –