Modifying Default Algebra Functions

This is a discussion on Modifying Default Algebra Functions within the C++ Programming forums, part of the General Programming Boards category; I want to know how to modify the default addition property of a class. For example, if I were to ...

Modifying Default Algebra Functions

I want to know how to modify the default addition property of a class. For example, if I were to create a class Complex, then the addition goes by adding the real components and the imaginary components. Suppose I have two complex numbers z1 and z2. I'd like it such that whenever I put: function (z1+z2) (here function is anything cout, return, parameter...). Then it would automatically use this addition rule, defined perhaps in the class.
I know a little Python, and it's very easy there, you just have to put:
def __add__(x,y): (the general way, not specifically this case)
return x + y
def __mult__(x,y):
return x*y