Re: template class instance
The choice of the template argument is determined at compile time, not run time, so taken at face value, what you are asking for cannot be done.
Anyway, what types may the user choose?
Re: template class instance
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.
Re: template class instance
Quote:
Originally Posted by
gotfell
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.
Re: template class instance
Quote:
Originally Posted by
gotfell
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.
Re: template class instance
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.
thanks