Changing the class data underneath some reference

Steven Schveighoffer schveiguy at yahoo.com
Thu Nov 30 04:18:37 UTC 2017


On 11/29/17 10:22 PM, Jonathan M Davis wrote:
> With classes, you could also assign the entire state of the object similar
> to what you'd get with structs and opAssign, but you'd have to write a
> member function to do it. There's no reason that you couldn't do the
> equivalent of opAssign. It's just that there's no built-in operator for it.
> So, whatever member function you wrote for it would be non-standard.
It's mostly a bad idea. The whole point of disallowing assignment is to 
prevent the slicing problem. It's also why opAssign isn't overloadable 
for classes assigning to classes in the same hierarchy.

-Steve


More information about the Digitalmars-d-learn mailing list