samedi 25 avril 2015

Template base type inheritance


I have an classes:

class Box{...};
class MyBox : public Box{...};

And an template:

template <type T>
class ObjectManager{...};

Which I use in some other class:

class Engine{
    ObjectManager<Box> * manager = nullptr;
    ...
};

Then I extend (implement) the Engine interface:

class MyEngine : public Engine{...}

And in that implementation (not earlier!) I know that manager should be like that:

MyEngine::MyEngine(){
    manager = new ObjectManager<MyBox>();
}

But this gives me an error because of types conflict (conversion between ObjectManager<Box> and ObjectManager<MyBox>), even when MyBox inherits from Box.

Is there any way around that problem? I don't want to modify the Box, MyBox, ObjectManager and Engine classes.


Aucun commentaire:

Enregistrer un commentaire