operator overloading

Hi All,

I had a very stupid doubt but I couldn't seem to understand this thing.

When I am overloading ++ operator , I need to provide int in the parameter and i can't use void. But essentially I am not using that variable as I am increasing the value of whatever is there only by a constt 1.

Why is it then, that i still need to provide and int parameter and void doesn't work ?

Sincerely,
Neeraj
The reason is that the compiler needs to differentiate between two operators with an identical symbol ++.

There is pre-increment ++i; and there is post-increment i++;

So to distinguish between the two the function signature needs to be different. So the int parameter is a bit of a hack to solve the ambiguity.
Topic archived. No new replies allowed.