I have a C++ template class that contains a method pointer and a class pointer, and who has single method, call, that calls the method pointer on the class pointer.
This template is called Method< C >, C being the class of the class and method pointers.
I want to create an array (std::vector) of this template, but I want this vector to be able to contain different classes of this template. My final goal is to go through this vector and call the call method of each of the elements, even if they have different classes.
How would you do that?
You can not store
templates invector, onlyobjectsthat havetypes. Andtemplatebecometypewhen it is instantiated.So, you can’t do exactly what you want.
I recommend you use
functionandbind. See an example:It does exactly you want.