samedi 5 mars 2022

How to pass a set of different kinds of templated components to a function?

I have components:

struct ComponentStorage : Storage{
    ...
};

template<typename T = ComponentStorage>
class Component{
public:
T* storage;
...
}

There are derived classes of the form:

struct Component2Storage : Storage{
    ...
};

template<typename T = Component2Storage>
class Component2 : public Component<T>{...}

There are multiple levels of inheritance both for Component and for Storage.

My question has to do with functions that with take a Component as input, for example:

void myFunction(unordered_set<Component*> components){...} // This won't compile

How do I modify my function so I can pass a set containing different kinds of components which may be using different kinds of storage? The actual function doesn't treat different kinds of components differently.

Aucun commentaire:

Enregistrer un commentaire