I am a newbie to C++, I have a question regarding to the c++ protected and private members in inheritance.
If a class is public inherits a based class, does the protected and private member variable will be part of derived class?
For example:
class Base
{
protected:
int a;
int b;
private:
int c;
int d;
public;
int q;
};
class Derived: public Base
{
};
does class Derived also have all the member of a, b, c, d, q
? and can we define a int a
as public, protected, and private in Derived class?
No class can access private
variables. Not even subclasses.
Only subclasses can access protected
variables.
All classes can access public
variables.