A
Alexander Stippler
Hello,
I want to build up an inheritance structure looking like two coupled dreaded
diamonds. It's similar to an old posting of me. Now my question is, where
to use the keyword virtual.
CV
/ \
/ \
V CDV
\ / \
\ / \
DV CMI
\ /
\ /
MI
I placed virtual like this:
V : public virtual CV
CDV : public virtual CV
DV : public virtual CDV, public V
CMI : public virtual CDV
MI : public DV, public CMI
My porblem is, that the construction process of an MI does not do the
conctructor calls, I would expect. There is a constructor
MI(const CDV &rhs) : DV(rhs) {} // CMI has a default constructor.
which calls
DV(const CDV &rhs) : V(rhs) {} // CDV has a default constructor.
and now I would expect
V(const CV &rhs) {} // CV has a default constructor.
to be called, but actually
V() {}
is called. And here I wonder. Where am I wrong. I hope I provided enough
information. Else ask please. All classes are template classes by the way,
if relevant.
regards,
alex
I want to build up an inheritance structure looking like two coupled dreaded
diamonds. It's similar to an old posting of me. Now my question is, where
to use the keyword virtual.
CV
/ \
/ \
V CDV
\ / \
\ / \
DV CMI
\ /
\ /
MI
I placed virtual like this:
V : public virtual CV
CDV : public virtual CV
DV : public virtual CDV, public V
CMI : public virtual CDV
MI : public DV, public CMI
My porblem is, that the construction process of an MI does not do the
conctructor calls, I would expect. There is a constructor
MI(const CDV &rhs) : DV(rhs) {} // CMI has a default constructor.
which calls
DV(const CDV &rhs) : V(rhs) {} // CDV has a default constructor.
and now I would expect
V(const CV &rhs) {} // CV has a default constructor.
to be called, but actually
V() {}
is called. And here I wonder. Where am I wrong. I hope I provided enough
information. Else ask please. All classes are template classes by the way,
if relevant.
regards,
alex