Re: why is it a class property cannot be used like a.b ~= c; ?

2021-09-04 Thread someone via Digitalmars-d-learn

On Saturday, 4 September 2021 at 23:57:09 UTC, jfondren wrote:

You're returning a copy of a slice, so if this compiled nothing 
useful would happen anyway. This works if `whatever()` returns 
`ref dstring` instead, with no other changes. Search 
https://dlang.org/spec/function.html for 'lvalue' and this pops 
right up.


At first glance it seems a bit counter-intuitive but yes, you are 
right, thanks for the link jfronden :)


Re: why is it a class property cannot be used like a.b ~= c; ?

2021-09-04 Thread jfondren via Digitalmars-d-learn

On Saturday, 4 September 2021 at 23:33:39 UTC, someone wrote:

```d
public class cSomething {

   private:

   dstring pstrWhatever = null;

   public:

   @safe dstring whatever() { return pstrWhatever; }
   @safe void whatever(const dstring lstrWhatever) { 
pstrWhatever = lstrWhatever; }


}

void main() {

   cSomething lobjSomething = new cSomething();
   lobjSomething.whatever = r"abc"d;
   lobjSomething.whatever ~= r"def"d; /// Error: 
`lobjSomething.whatever()` is not an lvalue and cannot be 
modified


}
```


You're returning a copy of a slice, so if this compiled nothing 
useful would happen anyway. This works if `whatever()` returns 
`ref dstring` instead, with no other changes. Search 
https://dlang.org/spec/function.html for 'lvalue' and this pops 
right up.


why is it a class property cannot be used like a.b ~= c; ?

2021-09-04 Thread someone via Digitalmars-d-learn

```d
public class cSomething {

   private:

   dstring pstrWhatever = null;

   public:

   @safe dstring whatever() { return pstrWhatever; }
   @safe void whatever(const dstring lstrWhatever) { pstrWhatever 
= lstrWhatever; }


}

void main() {

   cSomething lobjSomething = new cSomething();
   lobjSomething.whatever = r"abc"d;
   lobjSomething.whatever ~= r"def"d; /// Error: 
`lobjSomething.whatever()` is not an lvalue and cannot be modified


}
```