seesaw said:
Generally I´d suggest to get a good C++ book (like Accelerated C++ by A.
Koenig & B. Moo) where all these questions are covered in depth. However,
I´ll try to give a short answer which should give you an idea.
how does "private/protected" in inheritance change relationship between
classes
public inheritance represents "is-a" relationship, whereas this is not the
case with private inheritance. This means that a class B which is privately
derived from A is NOT an object of type A and hence cannot be converted to
one (at least not by the compiler). Furthermore, all members inherited from
A are instantly private members of B, no matter of their access type in
class A!
As a consequence of all this the relation of private inheritance is rather a
"implemented in terms of" relation, which of course is something that can
also be achieved by layering. For a detailed discussion of when to use
layering and when to use private inheritance I´d refer you to Effective C++
by Scott Meyers.
what is the purpose to define constructor as "private/protected"?
This way you prevent the user from directly constructing an object.
Consequently you can specify and regulate the way such an object is created
or you can indicate that the user should only use this class as a base
class.
is there any usage to define destructor as "private/protected"?
Yes, there is and I guess you also want to know which
Declaring a dtor
protected will prevent the deletion of an object via a pointer for example.
Another reason would be to indicate that a certain class can only be used as
a base class.
HTH
Chris