How to do multiple inheritance correctly in C++ using template classes?

54 views Asked by At

I have this derived class:

class Chart : public AsposeObjectWrapper<IChart>, public Shape, public Php::Base
    {
        public:
            Chart(System::SharedPtr<IChart> shape) : AsposeObjectWrapper<IChart>(shape), Shape(shape) {};
    }

And this base class:

class Shape : public AsposeObjectWrapper<IShape>, public Php::Base
{
    public:
        Shape(System::SharedPtr<IShape> shape) : AsposeObjectWrapper<IShape>(shape) {};

I can't make the inheritance work for several reasons.

1: the Shape constructor expects IShape pointer argument, while the Chart constructor receives only IChart (which is a subclass of IShape). Is it possible to convert IChart to IShape here:

 Chart(System::SharedPtr<IChart> shape) : AsposeObjectWrapper<IChart>(shape), Shape(shape) {};

2: Both Chart and Shape inherit from Php::Base, which is now ambiguous. However, I remove it from Chart class, it just won't work. Compiler will complain about stuff coming from that class. So Shape already has Php::Base as base class. Then Chart (derived from Shape) should just inherit all Php::Base functionality, right?

I'm a bit confused, don't know how to make this work. Basically, all I want is to make Chart inherit from Shape. What's the right way to do this?

0

There are 0 answers