www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - public vs private alias this

reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
When is it preferrable to use

```d
struct S { private T t; alias t this; }
```

instead of

```d
struct S { public T t; alias t this; }
```

for any given type `T`?
Nov 01 2022
parent Paul Backus <snarwin gmail.com> writes:
On Tuesday, 1 November 2022 at 23:01:57 UTC, Per Nordlöw wrote:
 When is it preferrable to use

 ```d
 struct S { private T t; alias t this; }
 ```

 instead of

 ```d
 struct S { public T t; alias t this; }
 ```

 for any given type `T`?
If the `alias this` needs to work outside the module where `S` is defined, you must make the member variable `public`. So in almost all cases, the second form is the correct one.
Nov 01 2022