从继承 类 调用匹配方法
Call matching methods from inherited classes
从继承了 3 个具有相同方法名称的其他基础 class 的单个 class 调用匹配方法的最佳方法是什么?我想从一次调用中调用这些方法,不知道是否可行
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
}
}
有什么办法吗?
谢谢
一次调用一次获取所有三个成员函数是不可能的。想象一下,这些成员函数 return 除了 void 之外还有其他东西:您期望哪个 return 值?!
如果你想调用所有三个碱基的on1msTimer()
类,你需要显式调用这些:
void onTimer()
{
fooBase<float>::on1msTimer();
fooBase<uint8_t>::on1msTimer();
fooBase<uint16_t>::on1msTimer();
}
从继承了 3 个具有相同方法名称的其他基础 class 的单个 class 调用匹配方法的最佳方法是什么?我想从一次调用中调用这些方法,不知道是否可行
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
}
}
有什么办法吗? 谢谢
一次调用一次获取所有三个成员函数是不可能的。想象一下,这些成员函数 return 除了 void 之外还有其他东西:您期望哪个 return 值?!
如果你想调用所有三个碱基的on1msTimer()
类,你需要显式调用这些:
void onTimer()
{
fooBase<float>::on1msTimer();
fooBase<uint8_t>::on1msTimer();
fooBase<uint16_t>::on1msTimer();
}