当我们从Object Oriented C++跨进Template C++,继承就不像以前那般畅行无阻了。
三个办法令C++“不进入templatized base classes观察”的行为失效——240
(1)在base class函数调用动作之前加上“this—>”:
template<typename Company>
class LoggingMsgSender:public MsgSender<Company>{
public:
...
void sendClearMsg(const MsgInfo& info)
{
...
this->sendClear(info); //ok
...
}
...
}
(2)使用using声明式:
template<typename Company>
class LoggingMsgSender:public MsgSender<Company>{
public:
using MsgSender<Company>::sendClear;
...
void sendClearMsg(const MsgInfo& info)
{
...
sendClear(info); //ok
...
}
...
}
(3)明确指出被调用函数位于基类内:
template<typename Company>
class LoggingMsgSender:public MsgSender<Company>{
public:
...
void sendClearMsg(const MsgInfo& info)
{
...
MsgSender<Company>::sendClear(info); //ok
...
}
...
}
总结——242
可在派生类模板内通过“this->”指涉基类模板内的成员名称,或藉由一个明白写出的“base class资格修饰符”完成。