有没有办法(模板,宏任何其他)在编译时替换从通用方法调用hidden_in_derived,以便 Derived 的实例调用它自己的hidden_in_derived(而不在 Base中使hidden_in_derived虚拟)?
#include <iostream>
class Base {
public:
void common() {
// some calls to other methods
hidden_in_derived();
// yet some calls to other methods
}
void hidden_in_derived() {
std::cout << "A" << std::endl;
}
};
class Derived : public Base {
public:
void hidden_in_derived() {
std::cout << "B" << std::endl;
}
};
int main() {
Derived d;
d.common(); // want hidden_in_derived (prints "B") here somehow ?
}