Re: String literals and templates
Aaron Graham wrote:
Frederick Gotham wrote:
The first question that comes to mind is, why don't you simply have the
following?:
template<class T>
void Foo(T const *);
If you only want an array to be passed, and if you want to
retain its length, then:
But my example implies that this is certainly not the case. I
don't just want arrays to be passed. Anything that has a
defined operator<< is allowed. That includes ints and
std::strings as well as char arrays and even user defined
serializable objects.
In which case, the simplest solution is probably to just provide
a non template function for the char const* case. This is what
I do in my ostream wrappers, and it seems to work. I wasn't
bothered by the number of functions, but the template version
didn't instantiate correctly, I forget why. Adding the non
templated overload made it work, however.
If you want to support manipulators as well, you'll also have to
provide a non-template version for them. Since the manipulators
themselves are template functions, the compiler really doesn't
have enough to go on otherwise for type deduction.
--
James Kanze GABI Software
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]