e.g
class A
{
public:
virtual const char* getName() { return "A"; }
};
class B: public A
{
public:
const char* getName() { return "B"; } // note: not virtual
};
class C: public B
{
public:
const char* getName() { return "C"; } // note: not virtual
};
class D: public C
{
public:
const char* getName() { return "D"; } // note: not virtual
};
int main()
{
C c;
B &rBase = c; // note: rBase is a B this time
std::cout << rBase.getName() << '\n';
return 0;
}
//虽然B没有virtual 修饰,但是继承了A和被继承了C而且有相同名字的方程,所以会被默认继承