[LC++]overloading operator[]

Mark Phillips mark at austrics.com.au
Thu Aug 30 10:24:05 UTC 2001


Julien Patrick Claassen wrote:
> 
> Hello all!
>   I wrote a small class for handling a specific config-file and that class
> should have a special operator[]. It should look like:
>   char* config_table::operator [] (char *field_name);
>   This operator should return a pointer to the field named field_name. The
> complete file is stored in a string. The file has a constant size and the
> elements, fields, have a constant position, but the position is a bit
> weird and I don't take all fields, so I decided to get the fields by name.
> For that reason I would apreciate it to have an operator[] like that. Can
> I do so? Or if not, which other, really good and convenent way can I
> choose.

I'm a little unsure about exactly what you want to do, but here is
what I think you are saying:

You have a file stored in a string, let's call it fileString.  You
want operator[] to return the position in fileString where the 
field_name field is located.  Why not use the STL hash_map to
map field names to string locations?

Hope this helps,

Mark.



More information about the tuxCPProgramming mailing list