lundi 23 janvier 2017

Is it possible to store different class with template member function in a container

That's a hard one for me. I need to store different classes with same template member function in one container. The member function is always the same declaration.

struct foo_creator {
  template < class T >
  base* create() {
    return new foo;
  }
};

struct bar_creator {
  template < class T >
  base* create() {
    return new bar;
  }
};

The functions are applied to multiple types. At time of storage I don't know the exact types on which I want to apply the functions. That's way I can't work with a base class.

Is there a way to store them in one container or at least something that let me apply the functions later when I know the concrete type?

I afraid that couldn't be solvable.

Anyway thanks in advance!

Aucun commentaire:

Enregistrer un commentaire