opAssign() still accepted for classes???

Alexander aldem+dmars at nk7.net
Fri Apr 29 08:20:16 PDT 2011


On 29.04.2011 17:05, Steven Schveighoffer wrote:

> opAssign is only invalid if you are assigning something that implicitly converts to that type.

  Well, the documentation says: "The assignment operator = can be overloaded if the lvalue is a struct aggregate, and opAssign is a member function of that aggregate."

  Thus, I assume that for classes it shouldn't be possible, or did I get it wrong?

> x = y is equivalent to x.opAssign(y).  So x is null, you are dereferencing a null pointer.

  This I understand, of course - the main point is why it is accepted for objects at all.

  BTW, it seems that overloads can be static - what is the semantic of static overload? (static opAssign() also fails).

/Alexander


More information about the Digitalmars-d mailing list