redirecting an operator to a property!

Hi to all, I'm trying to redirect the [] from a class to a property of that class

Class Myclass
{
bool myBool;
string myString;
map<int,string> myMap;
}


I wanted to do somethin like:

Myclass a;
a[0] = "hello world"

and it actually would set myMap[0] to hello world".

and
cout << a[0]

to print "hello world";

Possible??
Thank you in advance!
Yes, just overload the [] operator:

1
2
3
4
5
6
7
8
9
10
11
class Myclass
{
  //...

  string& operator [] (int index)
  {
    return myMap[index];
  }

  //...
};
Topic archived. No new replies allowed.