warning C4717: 'DollarsCents::operator+=' : recursive on all control paths, function will cause runtime stack overflow
warning C4717: 'DollarsCents::operator-=' : recursive on all control paths, function will cause runtime stack overflow
warning C4717: 'DollarsCents::operator/=' : recursive on all control paths, function will cause runtime stack overflow
warning C4717: 'DollarsCents::operator*=' : recursive on all control paths, function will cause runtime stack overflow
Warning C4717: Every path through a function contains a call to the function. Since there is no way to exit the function without first calling itself recursively, the function will never exit.
Line 3 You create a DollarCents object.
Line 4 You try to execute your operator overload on a DollarCents object.
So the compiler goes to its list of operators and says cool I have a method for dealing with DollarCents objects let me call it, cool I have a method for dealing with DollarCents objects let me call it, cool I have a method for dealing with DollarCents objects let me call it, and then we enter "Ground Hog Day."
mobotus is correct. Your operators are all calling themselves, so it's basically an infinite loop.
Also... your logic is incorrect anyway. The *=, +=, etc operators should be modifying this object... they should not be creating a new DollarsCents object.
Here... *this is a DollarsCents object. So what you're doing with this line of code is telling the computer to add two DollarsCents objects together.
The problem is... the computer doesn't know HOW to do that. The computer is going to look to your += operator to see how to add these two objects together.
So basically what's happening is this:
1) Computer needs to add two DollarsCents objects together.
2) It checks your += operator to see how to do that
3) Your += operator does it by adding two DollarsCents objects together
4) So in order to know how to add two DollarsCents objects, it needs to add two DollarsCents objects
5) So it checks your += operator to see how to do that
6) Your += operator does it by adding two DollarsCents objects together
7) etc
8) etc
Your += operator should be defining how to add the objects. So you probably need to access DollarsCents's members and add them rather than trying to add the object as a whole.
Oh lord I get it now, I think I've really been staring at this for too long, thank you all!! I'm getting some strange output though according to others in the class the sample output is completely wrong, so I'm not really sure where I stand in terms of this...if someone could check me that would be wonderful, I of course understand if you'd rather not...
The . is happening before the *, so the complier thinks you are saying that this is a class ( not a pointer to the instance ).
You can do: (*this).dollars, but since this is such a common thing to want to do ( dereference a pointer and then use it ), we are given the -> operator: