What should opAssign return, finally answered!
Charles D Hixson
charleshixsn at earthlink.net
Tue Oct 23 08:57:34 PDT 2007
downs 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?
> Variant is a struct.
> The this of a struct is a pointer.
> Ergo it has to dereference it, since opAssign returns the assignee for
> purposes of assignment chaining (a=b=c).
>
> Hope that clears things up.
> --downs
Thank you. Yes, that explains my confusion.
More information about the Digitalmars-d-learn
mailing list