Operator Overloading

Hello there!!!

I want to clear a doubt about overloading "++" operator.
when i overload the operator through the use of friend function why i need to pass the reference of the object as the argument?
I mean why i cant be able to pass the pointer insted of object reference?
Because the operator function signature ** by definition ** takes an object reference and not a pointer. You are overloading. There already exists a function overload for pointers. Note that pointer ++ does something very different from what you might intend. If you overloaded the function that takes pointers, pointer arithmetic on objects of that type would be broken.
Also the C++ standards says:
13.5.7 Increment and decrement

1 The user-defined function called operator++ implements the prefix and postfix ++ operator. If this function is
a member function with no parameters, or a non-member function with one parameter of class or enumeration
type, it defines the prefix increment operator ++ for objects of that type.
If the function is a member function
with one parameter (which shall be of type int) or a non-member function with two parameters (the second
of which shall be of type int), it defines the postfix increment operator ++ for objects of that type. When
the postfix increment is called as a result of using the ++ operator, the int argument will have value zero.
Well while overloading the functioning of every single operator can be broken.
we can do anything while overloading the "+" operator except addition.so i doubt that would be a perfect one.
and sorry to say but yes it is defined in the manual that the particular overloading process done only using with the references but the question is why is so?
references used there only there by that modification can be happened to the real objects and that work can be done with the help of pointers also.....
Topic archived. No new replies allowed.