alias this - am I using it wrong?
jfondren
julian.fondren at gmail.com
Wed Aug 25 12:18:46 UTC 2021
On Wednesday, 25 August 2021 at 12:11:01 UTC, Johann Lermer wrote:
> ```d
> 14 void main ()
> 15 {
> 16 auto ac = new Alias_Class;
> 17 Test_Struct ts = ac; // compiles
> 18 ac = ts; // compiles as well - why?
> 19
> 20 auto tc = new Test_Class;
> 21 ts = tc.ac; // compiles
> 22 tc.ac = ts; // again this compiles, but seg
> faults
> 23 }
> ```
line 17: ac.ts is copied into main's ts
line 18: main's ts is copied back into ac.ts
You can confirm this by changing t, doing the copy, and then
checking t.
line 21: segfaults because tc.ac is null, and you're trying to
copy tc.ac.ts into main's ts
More information about the Digitalmars-d-learn
mailing list