Function returning map address

Hi.

I'm trying to make a function that returns an address to some sort of map, for the purpose of assigning to or retrieving a value from said map.

The format I'm looking to achieve is the following:

1
2
varac('A') = foo;  //To assign foo to 'A' in the map
bar = varac('A');  //To assign value corresponding to 'A' to bar 

The varac function needs to be in the format:

1
2
3
4
5
6
7
variant &varac(char letter)
{
  if (<letter isn't found in the map>)
    <add letter to the map>;

  return <address location for the value in the map corresponding to letter key>;
} 


I can't differ from this format at all. So can this actually be done? Thanks a lot for any help. :)
Last edited on
basic reference retunrning syntax:
1
2
3
4
5
6
int x; //Global

int& foo()
{
    return x;
}

Elaborate further what you have problem with.
And why not use std::map
Ok that seems obvious. I just do: it = map.find(letter); return it->second; in the function format I placed above and it will work?

Ok thanks for the help lol :p
For some reason I wasn't seeing it so simply.
Last edited on
Topic archived. No new replies allowed.