I was trying out few concepts of function hiding in c++.
So here in the derived class I've used scope resolution operator using base::fun
to provide scope of base class in derived class. My objective is to print cout<<" base "<< x;
but the output only prints derived class cout. Any reasons why and how to solve? i.e it should print both base and derived class value. I'm new to c++, so sorry for any mistakes.The code is shown below:
#include <stdio.h>
#include <iostream>
using namespace std;
class base
{
public:
int fun(int x)
{
cout<<" base "<< x;
return x;
}
};
class derived:public base
{
public:
using base::fun;
void fun(int a)
{
cout<<" derived "<< a;
}
};
int main()
{
derived d;
d.fun(10);
return 0;
}