D1
has inherited variable Base::n
but it cannot access it.
Correct.
Private members of a class are never accessible from anywhere except the members of the same class.
D1
has inherited the function Base::method
but it doesn't call/modify this inherited function in the above implementation.
Correct, but conditonally, Read below for why:
D1
inherits the Base::method
but it is not calling/invoking it because you did'nt add any statement to do so. But it can call it.
Pure virtual functions can have a body and they can be called by drived class members just like any other member function.
class D1 : Base
{
public:
void doSomething()
{
Base::method();
}
};
Note that in your Base class n
is private so the only way to access it is through member function of Base & since only method()
can do so, You can do it through it.
Note that presence of atleast one pure virtual function makes an class Abstract Class, And one cannot create objects of an Abstract class. Any class deriving from an Abstract class must override ALL the pure virtual functions of the Base class or else the derived class becomes an Abstract class as well.
Based on above rule,
In your case both Base
and D1
are Abstract classes.
D2::method
is not an overridden version of D1::method
Incorrect
Though method()
is not acessible to the ouside world through instance of class D1
, it is still very much a part of it. Access control dictates access rights not presence or absence of members.
So, Yes, D2::method
is an overriden version of D1::method
and it hides it as well, just that in this case, D1::method
was not acccessible in the first place