wo*********@yahoo.com wrote:
I know that, when you pass an argument to a function
(if you want let the function be able to [modify] the value)
then you can choose to pass the argument
by reference or a pointer to that argument.
Now my question is,
"Why would you prefer to let a function return a reference or a pointer?"
Consider the following with operator overloading.
I suppose the operator can be seen as a function (right ?)
type operator-()
type& operator-()
1. Don't pass [non-const] references of pointers to functions.
2. If your function *must* modify one of it's arguments,
pass a reference or a pointer to the object then
return a reference or a pointer to that object
*instead of implementing a void function"
so that you can use the function in expressions.
You compiler will *not* be able to resolve an invocation
of operator-() to either of the two candidates above.
You must implement one or the other -- not both.
You will need to explain the [overloaded] meaning
of operator- before we can help you decide
whether to return a value or a reference
but built-in operator- *always* returns a value.