*this
Paul D. Anderson
paul.d.removethis.anderson at comcast.andthis.net
Fri Apr 24 14:12:00 PDT 2009
Don Wrote:
> Paul D. Anderson wrote:
> > Looking at Don Clugston's BigInt code I see usage of "*this":
> >
> > BigInt opMulAssign(T: BigInt)(T y) {
> > *this = mulInternal(*this, y);
> > return *this;
> > }
> >
> > I think I know what it does (passes this by reference) but I can't find any documentation that explains the usage. Can anyone point me to a source??
> >
> > Paul
> >
> >
> It's passing by value, since BigInt is a struct, not a class. 'this' is
> a pointer to the struct, so *this is the struct itself. In the case of
> BigInt, the struct only contains an bool and a dynamic array, for a
> total of 10 bytes or so, so it's not much bigger than a pointer.
>
> I believe the behaviour of 'this' in structs changed recently (but
> probably only in D2?) The BigInt wrapper class would be a bit different
> in D2.
>
> BTW BigInt uses structs, not classes, and part of the reason for this is
> that you _cannot_ have value semantics with a class.
>
Thanks, Don.
Paul
More information about the Digitalmars-d-learn
mailing list