class base{
.....
virtual void function1();
virtual void function2();
};
class derived::public base{
int function1();
int function2();
};
int main()
{
derived d;
base *b = &d;
int k = b->function1() // Why use this instead of the following line?
int k = d.function1(); // With this, the need for virtual functions is gone, right?
}
Run Code Online (Sandbox Code Playgroud)
我不是CompSci工程师,我想知道这一点.如果我们可以避免基类指针,为什么要使用虚函数?