Ref and class function calls?
Tofu Ninja
emmons0 at purdue.edu
Tue Apr 16 08:44:20 PDT 2013
On Tuesday, 16 April 2013 at 15:27:10 UTC, Ali Çehreli wrote:
> On 04/16/2013 07:57 AM, Tofu Ninja wrote:
> It would be bad design if a class variable decided to refer to
> another object without the owner of that variable knowing about
> it.
I don't know, It seems like the caller of the function should
know what he/she is calling. I don't make practice of calling a
function with out knowing what it will do first, the caller
should know that their is a chance the variable would be
reassigned if its a 'ref this function'.
The same thing can be said about normal ref arguments. The caller
knows that if they pass a variable into a function that has a ref
argument, then there's a chance that the variable will be
reassigned. Its the responsibility of the caller to know what
they are calling and what might happen because of it.
And their are plenty of cases that a 'ref this function' is
desirable. Simple example, a linked list head with a push
function. It reassigns the head variable to what you are pushing
and chains the rest after it. It makes logical sense to be able
to do head.push(...) and it makes sense for this to be a class
function.
Tofu
More information about the Digitalmars-d-learn
mailing list