Sum of 2 values from map with string keys

Hey everyone. I'm trying to add the sum of 2 double values from a map who have a string key. I think the operator[] needs to be overloaded to accomplish this.

Here is what I have so far:

1
2
3
4
5
6
7
8
9
10
class Items
{
public:
	void add(string name, double price);
	double& operator[](double index);

private:
	map<string, double> items;
	multimap<double, string> inverse_items;
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
	Items testing;
	testing.add("Item1", 19.95);
	testing.add("Item2", 24.95);
	testing.add("Item3", 8.99);

	// need to overload [] operator for this to work
	double total = prices["Item1"] + prices["Item2"];
        cout << total;
	cout << prices["Item1"];

	system("pause");
	return 0;
}


Here is where I need help - I stink at overloading.
1
2
3
4
int& Items::operator[](int index)
{
	return items[index];
}


Thanks in advance for the time and help.
Topic archived. No new replies allowed.