I have just started learning about inheritance and I know that private members of base class are not inherited by the derived class.
But when I run the 'get_data1' function of the derived class, it returns the value of data1 from the base class even though I have defined a new 'data1' in the derived class. So shouldn't it return 3 instead of 5 as it is a member function of the derived class?
class base
{
int data1;
public:
base()
{
data1=5;
}
int get_data1()
{
return data1;
}
};
class derived : public base
{
int data1;
public:
derived()
{
data1=3;
}
void printData()
{
cout<<get_data1()<<endl;
}
};
int main()
{
derived der1;
der1.printData();
return 0;
}