questions involving inheritance

i have a few questions involving what and what isnt inherited from base classes.

this basically just pertains to access modifiers. lets say i have a class like this
1
2
3
4
5
6
7
8
9
10
11
class base_class
{
int randomVariable;
protected:
	int var1, var2;
public:
	int function()
	{
		return var1 * var2;
	}
};


if i then create a class derived from this and change its access modifier to private so the derived class looks like this:
1
2
3
4
5
6
7
8
9
class derived_class:private base_class
{
	int variable;
public:
	int anotherFunction()
	{
		return variable * 2;
	}
};


then would the derived class have access to the private members of the base_class? the same for protected and public, if i change the derived_classes modifier what will it gain or lose access too?

thank you!
derived_class can still access public and protected members of base_class.

The difference is that outside code cannot access the base_class of a derived_class object.

Example:

1
2
3
derived_class d;
base_class* b = d;  // OK if public inheritance
   // Error if private inhertiance, because base_class is private to derived_class 
Topic archived. No new replies allowed.