Can I call the default opAssign after overloading opAssign?
Jonathan M Davis
jmdavisProg at gmx.com
Sun Nov 18 22:32:27 PST 2012
On Monday, November 19, 2012 07:21:10 Rob T wrote:
> I think you've cleared things up for me.
>
> When I define an opAssign, I'm not really overriding a default
> opAssign, because there is none, instead I'm overriding the
> default behavior which is to perform a memcopy-like operation.
>
> So if I defined an opAssign function, but for some odd reason I
> wanted to execute the default assignment behavior, then I can
> still do it by performing a memcopy-like operation, perhaps best
> done using the C libs memcopy function.
>
> Correct?
I'm not sure. Close certainly. But if any member variables define an opAssign,
then the compiler probably calls them rather than doing a simple memcpy. I'm
not sure though. If it does, then a memcpy would not exhibit the same
behavior, and the only way to get the same behavior would be to copy each
member variable one by one. If it doesn't, then a memcpy would do the same
thing as the default behavior.
I am a bit worried though as to why you'd even want to skip opAssign like
that. At the moment, I can't think of any legitimate use cases for doing that
(though that obviously doesn't mean that you don't have one).
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list