Nov 20, 2012 at 10:16am UTC
Hi
I've template class that may get string and integer,
if I'm using it with int it's fine but if I use it with string I get an error,
because string need to be "" and not NULL.
what can I do?
this is the code:
1 2 3 4 5
template <class K>
Item<K>::Item()
{
key=NULL;
}
Last edited on Nov 20, 2012 at 10:17am UTC
Nov 20, 2012 at 10:22am UTC
thank you, but It's good to string but error for int
Last edited on Nov 20, 2012 at 10:23am UTC
Nov 20, 2012 at 10:27am UTC
Nope, it's good for both. Did you compile it?
If you get an error, get a more recent version of your compiler.
Nov 20, 2012 at 10:29am UTC
my mistake
It's fine
thank you
Nov 20, 2012 at 10:31am UTC
It's better to initialize key in the constructor initialization list.
1 2 3 4 5
template <class K>
Item<K>::Item()
: key()
{
}
Last edited on Nov 20, 2012 at 10:32am UTC