条款43:学习处理模板化基类内的名称
class CompanyA {
public:
...
void sendClearText(const std::string& msg);
...
};
class CompanyB {
public:
...
void sendClearText(const std::string& msg);
...
};
class MsgInfo { ... }
template<typename Company> // 基类
class MsgSender {
public:
...
void sendClear(const MsgInfo& info) {
std::string msg;
Company c;
c.sendClearText(msg);
}
};
template<typename Company>
class LoggingMsgSender: public MsgSender<Company> {
public:
...
void sendClearMsg(const MsgInfo& info) {
... // 发送前操作;
sendClear(info); // 调用基类的发送实现,编译不通过;
... // 发送后操作;
}
};Last updated