What should opAssign return?
Charles D Hixson
charleshixsn at earthlink.net
Mon Oct 22 23:47:54 PDT 2007
Nathan Reed wrote:
> Charles D Hixson wrote:
>> What I would expect is:
>>
>> class A
>> {
>> A opAssign(A a)
>> {
>> // do stuff here
>> return this;
>> }
>> }
>>
>> but the only examples that I can find (variant.d) return *this ...
>> which leaves me quite confused. Is this something special that
>> Variant is doing to allow it to handle multiple types (I didn't follow
>> the internals), or do I have what is supposed to be returned wrong?
>
> 'this' is a pointer to the object, so '*this' is (a reference to) the
> actual object.
>
> Thanks,
> Nathan Reed
Sorry, I'm sure you think you answered the question, but I'm
as confused as before.
Are you saying that *this is the correct thing to return?
(I know that "*this" means a pointer to this, and that "this"
is a pointer to the object being created, but that doesn't
help me at the point where I am confused. I still don't know
what should be returned.)
More information about the Digitalmars-d-learn
mailing list