Reputation: 581
class base {
public:
int getC() {return c;}
int a;
protected:
int b;
private:
int c;
}
class derived: public base {
public:
int getD() {return d;}
private:
int d;
}
Now, class derived has public member:
int getC() {return c;}
int getD() {return d;}
int a;
protected member:
int b;
private member:
int d;
I can't comfirm if int c;
is a private member of class derived. It's clear that any new member function of class derived
can't access c
. So, if c
is a private member of class derived
, the member function of class derived
should have right to access c
. So c
is a what kind of member of class derived?
Upvotes: 1
Views: 1226
Reputation: 1222
I will clarify this with an example.
Now coming to the question each class access modifier has the following arrangement
base
private : int c;
protected : int b;
public : int getC() {return c;}
int a;
derived
private : int d; (derived will never know c's existense)
protected : int b; (base class's copy)
public : int getC() {return c;}
int a;
int getD() {return d;}
Upvotes: 0
Reputation: 285
A derived class doesn't inherit access to private data members. However, it does inherit a full parent object, which contains any private members which that class declares.
Have a look at this question
Upvotes: 1