/*Orion Lawlor's Simple C++ Examples, olawlor@acm.org
Shows how to overload a class foo's bracket 
(array index) operator.
*/
#include <iostream>

class foo {
private:
	double myVal;
public:
	double &operator[](int index) {
		std::cout<<"Called foo's operator[] with "<<index<<std::endl;
		return myVal;
	}
};

int main()
{
	foo f;
	f[3]=2.8;
	double x=f[7];
	std::cout<<"f[7]=="<<x<<std::endl;
	return 0;
}
/*<@>
<@> ******** Program output: ********
<@> Called foo's operator[] with 3
<@> Called foo's operator[] with 7
<@> f[7]==2.8
<@> */
