main 的以下输出的答案是“i=10 的派生类显示”,但我不明白为什么?确定该函数是在基本类型上调用的吗?
在这里确定答案的思考过程是什么?
class base
{
public:
virtual void display(int i = 10)
{
cout<<"Base class display with i = "<<i<<endl;
}
};
class derived : public base
{
public:
void display(int i = 20)
{
cout<<"Derived class display with i = "<< i <<endl;
}
};
int main(int argc, char *argv[])
{
base *bptr = new derived;
bptr->display();
return 0;
}