[vtk-developers] Multiple inheritance in an InteractorStyle subclass

David Cole david.cole at kitware.com
Thu Aug 25 17:13:48 EDT 2011


On Thu, Aug 25, 2011 at 4:54 PM, David Doria <daviddoria at gmail.com> wrote:
> I want to have this setup:
> Superclass:
> PointSelectionStyle - derives from vtkInteractorStyle, defines some virtual
> functions like AddPoint, DeletePoint, etc
> Subclasses:
> PointSelectionStyle2D - derives from vtkInteractorStyleImage
> and PointSelectionStyle
> PointSelectionStyle3D - derives from vtkInteractorStyleTrackballCamera
> and PointSelectionStyle
> The problem is here:
> class PointSelectionStyle2D : public vtkInteractorStyleImage, public
> PointSelectionStyle
> {
>   public:
>     static PointSelectionStyle2D* New();
>     vtkTypeMacro(PointSelectionStyle2D, vtkInteractorStyleImage);
> on the vtkTypeMacro line, I get:
> PointSelectionStyle2D.h:37:5: error: ‘vtkObjectBase’ is an ambiguous base of
> ‘PointSelectionStyle2D’
> After some Googling, it seems like I need to use virtual inheritance:
> class PointSelectionStyle : virtual public vtkInteractorStyle
> but I guess the problem is that vtkInteractorStyleImage does not virtually
> inherit vtkInteractorStyle as well? Is there anything that can be done here?
> Thanks,
>
> David
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>
>

I would recommend finding another way to accomplish your goal that
does not require multiple inheritance.

Could you compose an instance of your PointSelectionStyle class as a
data member of PointSelectionStyle2D and PointSelectionStyle3D?

I know I personally find composition much easier to understand than
multiple inheritance, unless the multiply inherited classes are
utterly trivial...



More information about the vtk-developers mailing list