0

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?

user2297996
  • 1,382
  • 3
  • 18
  • 28
  • "How to do multiple inheritance [...] ?" don't do multiple inheritance (unless you really really have to) – bolov Dec 11 '20 at 10:58
  • Well, that's not really possible in this case. I can't avoid it. – user2297996 Dec 11 '20 at 11:00
  • This looks pretty messy... I'd try to avoid multiple inheritance whenever possible. But to the points... 1. It is possible, yes, but you should ideally pass a base class pointer (i.e. IShape) pointing to a derived class object. 2. Yes, you need to remove the direct inheritence in IChart, and it will get access to Php::Base. I don't know what "Compiler will complain about stuff coming from that class. " means. – Cedric Dec 11 '20 at 11:02
  • 1
    Virtual inheritance might be the key to solve this, but I am not sure. https://www.cprogramming.com/tutorial/virtual_inheritance.html However, I agree with Cedric that this looks very messy. I think a class redesign might be helpful as well. – F K Dec 11 '20 at 11:00
  • virtual inheritance solve the diamond problem, but like already pointed out it seems very messy. – Moia Dec 11 '20 at 14:58

0 Answers0