I'm trying to understand, need your help as i'm unclear
Is private member of Base class is created in derived class?
as i know private member of base class cannot be inherited in derived class, but i'm able to print the parent(base) class members values by making base pointer to derived type.
(plz note i'm not looking for virtual functions)
Have copied the below piece of code:
$./a.out
vales=2 3
How the values a & b is created as its private
I understand in case of protected could have inherited , please correct me if i'm wrong
-------------------------
class A {
int a, b;
public:
A(int x, int y) { a = x; b =y; }
void print ()
{
cout<<"values="<<a<<" "<<b<<endl;
}
};
class B: public A
{
int m;
public:
B(int b1, int b2, int b3) : A(b1, b2)
{
m = b3;
}
void print ()
{
cout<<"value="<<m<<endl;
}
};
main()
{
A * ptr;
B t(2,3,4);
ptr = &t;
ptr->print();
}