How to overload two operators at once?

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	string operator[](string inindex)
	{
		SplendidList * conductor = root;
		while (conductor != NULL)
		{
			if (conductor->key == inindex)
			{
				return conductor->value;
			}
			conductor = conductor->next;
		}

		delete conductor;
		return "INVALID KEY";
	}


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.
Last edited on
Topic archived. No new replies allowed.