Inheritance problem

Hi,

I have an abstract base class - let's call it MyInterface - and a class that most classes in my program inherit from, let's call it MyBaseclass.

Let's assume that all my objects inherit MyBaseclass, some of which also inherit MyInterface. Now I want to collect objects in a container class, MyContainerclass. The container class is only interested in objects that implement MyInterface.

Now I know that all objects that inherit MyInterface also inherit MyBaseclass, but the compiler doesn't know that. MyContainerclass wants to call methods in MyBaseclass, but it collects pointers to MyInterface classes. I can't make MyInterface inherit MyBaseclass, because I will be using classes that I don't want to change (they are part of a framework) that already inherit MyContainerclass. IOW, I can't use virtual inheritance to get a nice inheritance diamond.

To sum up, I want to create a container class that:
1. Collects objects that implement MyInterface.
2. Calls MyBaseclass methods on the collected objects.

I'm not sure how to solve this... I'd appreciate any help.

Thanks in advance!
Use duck typing with templates.

Or make your container accept objects of MyBaseClass. As all your objects inheriting from MyInterface inherits from MyBaseClass too, it should accomodate all of them.
Your comment made me start thinking in a new direction, I've solved it now (and quickly, once I started to get it). Thank you!
Topic archived. No new replies allowed.