So now you ask, what is this operator overloading stuff, how will it help me make the supreme burrito, and what the heck does "binary operator overloading" mean? Lets take this one step at a time. First, a quick example of operator overloading. #include <iostream.h> class Burrito { private: int amtbeef, amtbean; public: Burrito(int beef, int bean) { amtbeef = beef; amtbean = bean; } Burrito operator + (Burrito newburrito) { int newbeef = amtbeef + newburrito.amtbeef; int newbean = amtbean + newburrito.amtbean; return Burrito(newbeef, newbean); } }; void main(void) { Burrito b1(5,10), b2(10,5), b3; b3 = b1 + b2; } Notice a couple things about the method which defines the "+" operator for the Burrito class:
So now we can go use this class to make gratuitous use of the overloaded "+" operator in our pgram to find the supreme burrito, without having to type addburrito a lot. So we can program faster, and thus find the supreme burrito faster. A win-win situation! |