On Thursday, September 13, 2018 4:04:58 AM MDT Jan via Digitalmars-d-learn wrote: > Many thanks Adam and Steve! Works like a charm! :D > I presumed classes are lvalues. I shouldn't make things more > complicated than they are ;-)
Well, the variables _are_ lvalues. It's just that they're references to objects rather than the objects themselves. You never refer to a class object directly in D. Rather, you're always dealing with a reference to a class object. Class references are basically pointers except that you can't dereference them directly, just call member functions on them (which in D means implicitly dereferencing whether you're talking about pointers or class references). In that respect, they're like classes in Java. So, if you assign a value to a class reference, you're assigning the reference, not the class object itself, just like when you assign a value to a pointer, you're mutating the pointer itself, not mutating the object that it points to. - Jonathan M Davis