Hi all, I'm working on a project that creates a stack using a template class. My problem is I'm trying to make it so the user decides what kind of data type(int, string, float, etc.) the stack will use but I can't seem to think of a way to instantiate the template class with declaring a type for it before compile-time. IS what I'm trying to accomplish even feasible or do I have to set the data type before it compiles?
Yes. Besides, how were you planning on creating objects of the selected type anyway? And what were their values supposed to be? Try to explain what you're trying to do, because there's always a solution (unless it was a question of theoretical nature).
Can I cause some trouble with a vector<void*> here?
Not saying the following is a good idea, just that it's possible:
1) Prompt user for the type to be stored. I'll use a char code for this: char typeCode;// char = 'c', int = 'i', float = 'f'
and store pointers to the values in a vector: vector<void*> pDataVec;
2) Prompt user for data values in a switch statement: