Multiple subtyping with alias this and nested classes
Sergey Gromov
snake.scaly at gmail.com
Sun Oct 4 06:03:30 PDT 2009
Sun, 04 Oct 2009 00:10:30 +0200, Yigal Chripun wrote:
> > interface IBlipper
> > {
> > void blip();
> > void nameCollision();
> > }
> > template Blipper()
> > {
> > void blip() {}
> > void nameCollision() {}
> > }
> >
> > interface IFlipper
> > {
> > void flip();
> > void nameCollision();
> > }
> > template Flipper()
> > {
> > void flip() {}
> > void nameCollision() {}
> > }
>
> interfaces implement virtual MI, so FlippingBlipper must implement one
> nameCollision which is shared by both interfaces.
That's not correct if you're talking about virtual MI in C++. There,
you'd have to create a common root for the virtual inheritance to
actually work:
class INameCollider
{
public:
virtual void nameCollision() = 0;
};
class IFlipper: public virtual INameCollider
{
public:
virtual void flip() = 0;
};
class IBlipper: public virtual INameCollider
{
public:
virtual void blip() = 0;
};
class FlippingBlipper: public IFlipper, public IBlipper
{
public:
// Contains single, common nameCollision()
virtual void nameCollision() {}
virtual void flip() {}
virtual void blip() {}
};
Otherwise, if IFlipper and IBlipper are unrelated, you have two separate
nameCollision() functions which you must disambiguate as
IFlipper::nameCollision() and IBlipper::nameCollision() both when
defining and when calling via a FlippingBlipper instance.
More information about the Digitalmars-d
mailing list