Overloading operators to add a class and an integer

I need to overload an operator, actually all of the binary and I am struggling to why my code doesn't work I hope some one can help

1
2
3

friend int operator+(int i, Money m){return m+i;}


I am trying to add an integer and a m which is a class. I was able to add and compare classes, but adding an integer and a class is just not working.

Furthermore, can I also add a regular numbers and classes this way?
For instance, m + 2, and get a result?
Thanks guys
closed account (SECMoG1T)
All you say is possible but the way you do it isn't right
Here ↓
{return m+i;}
Well to do it the tight way know that you can't add m to an int unless you have specified a way to convert the m Object to int or another numeric type such as float or convert to char.

Another way is to add an specific integral or numeric member of the class to the int .

E.g.
1
2
return m.pay+i;///where pay can be a float type or int, however i wont recommend conversion of
           ///float type to int due to loss of precision in the result. 
Topic archived. No new replies allowed.