请教,在中间类中定义一个空的虚函数起什么作用?最好能举例说明,感谢!
如题!
#include <iostream> using namespace std; class A { public: virtual void print() { cout << "A" << endl; } }; class B : public A {}; class C : public B { public: void print() { cout << "C" << endl; } }; int main() { C c; static_cast<A&>(c).print(); }输出: