使用base默认参数值C ++调用派生类函数

时间:2018-03-15 13:03:31

标签: c++ polymorphism virtual default-value

请有人解释波伏瓦吗?它使用Base的默认参数调用Derived&#39的函数?它的打印10 Derived's f():

#include <iostream>

class Base
{
public:
     virtual void f(int x=10)
     {
          std::cout<<x<<"  Base f()"<<std::endl;
     }
};

class Derived : public Base
{
public:
      virtual void f(int x=20)
      {
           std::cout<<x<<"  Derived f()"<<std::endl;
      }
};

int main()
{
     Base* bp = new Derived();
     bp->f();
}

0 个答案:

没有答案