Re: [ROOT] Operator overloading [silly question]

From: Ashley Cambrell (ash@freaky-namuh.com)
Date: Fri Apr 26 2002 - 17:13:19 MEST


Hi Fons,

Fons Rademakers wrote:

>Hi Ashley,
>
> for td["jane"] = "anderson"; to work you need something like:
>
>  
>
Wouldn't value be empty if value isn't found by FindObject?  Or
does "anderson" get assigned to the pointer to the string that gets
returned by value->String()?

So confusing :-P

>TString &THTTPMap::operator[](const char *key)
>{
>   TObjectString *value = (TObjString*)FindObject(key);
>   if (!value)
>      value = new TObjString;
>      Add(new TObjString(key), value);
>   }
>   return value->String();
>}
>
>
>Cheers, Fons.
>
>
>  
>
also, your one above seems to take precidence over

const TString& operator[](const char* key) const;

when doing:

cout << td["bob"] << endl;

Thanks Fons for the help

Ashley Cambrell



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:51 MET