about overloading

1
2
3
4
5
6
7
8
dimension dimension::operator++(void)
++inches;
return*this;

void main(void) {
dimension one(4,5); dimension two = ++one
//both object = 4 feet 6 inches 


1
2
3
4
5
6
7
dimension dimension::operator++(void)
inches++;
return*this;

void main(void) {
dimension one(4,5); dimension two = one++
//one.inches = 6 feet 6 inches and two.inches = 5  


why just simply changing the position of ++ will give 4 feet 6 inches for both if ++inches and 6 feet 6 inches for one.inches for inches++? i don't get it anyone can explain it to me? (please ignore my syntax errors i am just being lazy).
the change in your ++ operator doesn't make any difference ( notice that that's the overload only for the prefix ++ )
The second code does what is expected to do if you had a postfix ++ overloaded, if you don't your compiler is providing you one based on the prefix one.
See
http://www.cplusplus.com/doc/tutorial/operators/
http://www.cplusplus.com/doc/tutorial/classes2/
For more details
Topic archived. No new replies allowed.