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

class foo {
private:
	double val;
public:
	foo(double x):val(x) {}
	
	foo operator+(const foo &other) {
		std::cout<<"Called foo's operator+() with "
			<<this->val<<","<<other.val<<std::endl;
		return foo(this->val+other.val);
	}
};

int main()
{
	foo x(1.2),y(2.3),z(10.1);
	foo sum=x+y;
	foo sum2=x+y+z;
	return 0;
}
/*<@>
<@> ******** Program output: ********
<@> Called foo's operator+() with 1.2,2.3
<@> Called foo's operator+() with 1.2,2.3
<@> Called foo's operator+() with 3.5,10.1
<@> */
