[Cs3] Question during class today

Mikhail Nesterenko mikhail at cs.kent.edu
Fri Apr 3 17:04:00 EDT 2020


> 
> Today in class I asked if when using multiple inheritance if it mattered
> the order of access types.
> 
> For example does it matter if you did:
> 
> class C: public A, private B
> class C: private A, public B
> 

It turns out that in general the order of inheritance list _does_ make
a difference. The ivocation of the constructors of the base classes is
carried out in the order they are listed. That is, in your first
example, for an object of class C, first, constructor of class A is
invoked, then constructor of class B.  For destructor invocation, the
order is reverse.

Now, for the Adapter Design Pattern, the private inheritance is used
for the adaptee class, while public -- for the target. So, in your
example, in the first line A is the target while B is the adaptee; in
the second line, A is the adaptee and B is the target.

Is this order going to make a difference? Not for this
pattern. However, to me, stylistically, "target" then "adapte" seems
like the proper order.

Thanks,
--
Mikhail 


More information about the cs3 mailing list