1

Please can anyone explain the Beauvoir? It calling Derived's function with Base's default argument? Its printing 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();
}
Eduard Rostomyan
  • 7,050
  • 2
  • 37
  • 76

0 Answers0