基类指针通过子类的虚函数调用子类的非虚函数
class A {
public:
virtual void op();
……
};
class B : public A {
public:
void op(); // 在这个函数中会调用anotherOperator,但anotherOperator不是虚函数
void anotherOp();
……
};
A* a = new B;
a->op();// OK
class A {
public:
virtual void op();
……
};
class B : public A {
public:
void op(); // 在这个函数中会调用anotherOperator,但anotherOperator不是虚函数
void anotherOp();
……
};
A* a = new B;
a->op();// OK