Hi.
I'm trying to build a php style associative array class just for sport where it's basically a linked list
So I overload the [] operator to be used for index.
For example, I created this method
Like so:
which basically allows me to do this:
cout << mylist["my key"] << endl; which would run through a linked list of objects, and if it encountered the key "my key", it'd output the value of that node.
Now, I'd like to somehow overload both the [] and = operators so that I could do something liket his mylist["my key"] = "My value goes here";
What would be the syntax of that?
Let operator[] return a reference to the string value instead of a copy. That will allow you to assign using the syntax that you want. That's how std::map and all the other standard containers that have operator[] do it.