In the example, d2.basemem() is error. I don't know why, basemem is
private member function in the derived class d2, but d2 can use its own
member function, no matter what type it is.
Try to post code...
From the book, but somehow snipped:
class Base {
public:
void basemem();
protected:
int i;
};
struct Public_derived : public Base {
int use_base() {return i;}
};
struct Private_derived : private Base {
int use_base() {return i;}
};
And the lines the OP was refering to:
Base b;
Public_derived d1;
Private_derived d2;
b.basemem(); // ok...
d1.basemem(); // ok...
d2.basemem(); // error...
The problem, dear OP, is that d2 may use all functions from its base
B, but functions *outside* d2 may not use those inherited from Base.
See it this way:
The public part of a class is the outside image you let the rest see.
The protected part is the purse, you only let your family
(descendants) see.
The private part lies within your underpants.
If one of your descendants is proud of you, he inherits publicly form
you and puts your photo on a badge on the lapel, for everyone to see.
But if you embarrass him, and wants to hide the fact that he inherits
from you, he will do it privately. He is putiing you within his
underpants, no way for the others to see you.
Maybe that helps you understand the idea of the kinds of inheritance.
Regards,
Zara