On Thursday, 23 June 2022 at 16:08:01 UTC, Ola Fosheim Grøstad
wrote:
How am I supposed to write this:
```d
import std;
@safe:
struct node {
node* next;
}
auto connect(scope node* a, scope node* b)
{
a.next = b;
}
void main()
{
node x;
node y;
connect(&x,&y);
}
```
Error: scope variable `b` assigned to non-scope `(*a).next`
Why you should use `scope` here? A `scope` pointer variable may
refer to a stack allocated object that may be destroyed once the
function returns.
Since a linked list should not contain pointers to stack
allocated data you should avoid entirely the `scope` attribute
and use instead `const`.