+ 8
array of types
can I have a map of types ? I have an array of pointers to a base class every element refers to a son of this base I want to type cast to the son with something like map of array so instead of doing that if(a[i]->gettype()=="type1") ((type1*)a[i])->doit(); else if(a[i]->getttype()=="type2") ((type2)a[i])->doit(); I want to do something like ((type[k])a[i])->doit();
4 Respuestas
+ 3
good thing but my problem not in declaration type
I want to write a list on a file but I don't know what is the type of object I have in the element
+ 2
Try using decltype function.
template<typename T>
T func(T value) {}
dectltype(func(2)) v;
Here, dcltype returns the type of the return value of function func. (int in that example)
+ 2
interested.....
+ 2
Are all the types stored in your array derived from a common base class? If yes, then you can use polymorphism. Else... I don't know