class B{
private:
void DoSomething();
}
class W{
private:
class D: public B{
}
D d;
}
Can I call private member function in base class of D in the scope of class W?
class B{
private:
void DoSomething();
}
class W{
private:
class D: public B{
}
D d;
}
Can I call private member function in base class of D in the scope of class W?
Nope. You can never call a private member function from anywhere except the class that owns it. If you want derived classes to be able to access it, declare it protected instead.
You can also declare D to be a 'friend' of class B; that would allow D to access B.DoSomething(). However, this approach is usually frowned upon.
The function DoSomething can be accessed outside the class only if it is declared as public or private. Besides as mentioned above by Aric, the inherited class can become a friend to achieve the same.
The alternative approach would be to declare/define the function as virtual and do not define the virtual definition for the sub/inherited class. Doing this, will call the function definition for the base class.
No, if you use the protected keyword then you can. The fact that it is a nested class is irrelevant.