Hello, i have a class that is a template, I have to declare it in my main but i want the user to choose what type of data they will use in the class, I cant just declare myclass my, i have to use myclass<int> my, how can I change so user can select the proper datatype to use in the class.
its for a hashtables that could contain char,string,int,double,float. maybe its better i create many hashtables of types i need and just overload functions to put the data into correct hashtable.
its for a hashtables that could contain char,string,int,double,float.
you can instantiate the template with a type modeling all of them, dynamically. You can use boost variant for a ready-made solution ( if I recall correctly, it automatically inherits the comparison operators of its costituent types, so it would work immediately with associative containers; that said, adding hash support should be easy anyway ); otherwise, you can easily write your own "dynamic" type implementation ...
of course, as mentioned by laserlight, note that all this would defeat the benefit of compile time instantiation.
its for a hashtables that could contain char,string,int,double,float. maybe its better i create many hashtables of types i need and just overload functions to put the data into correct hashtable.
Why do you want to instances of those types in a single container? If you describe at a higher level what you want to achieve, you'll probably get better advice on what design is suitable.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Hi, Sorry i was a big vague, no i didnt want them in a single container, i just wanted to save having many hashtables lying around, but actually its worked out better making tables of ints, char and the rest and having overloads just place them in the right container. Thanks to the original reply i know a bit more about using templates in my hashmaps.
Bookmarks