Re: overloading << for map and multimap simultaneously
On Jul 29, 3:00 pm, ozizus <o...@ce.yildiz.edu.tr> wrote:
I overloaded operator << for STL map successfully:
template <typename T1, typename T2> ostream & operator << (ostream &
o, map <T1,T2> & m)
{
//code
}
the code works like a charm.
Are you sure? In what namespace did you put it? If you put it
in std, then you have undefined behavior. And if you put it in
some other namespace, if you use it in a template, the compiler
will only find it when it is instantiated on a class in the same
namespace (dependant name look-up oblige).
In general, you can't reliably overload operator<< generically
for any of the container types in the standard library (nor can
you overload it for instantiations where only standard types are
involved). In general, of course, you don't want to either.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34