Is there anyway to Deify the following code snippet?
WhatMeWorry
kheaser at gmail.com
Tue Apr 15 21:06:30 UTC 2025
I had assumed that ref keyword negated the use of * and &
operators but when I try to use it, DMD is saying "only
parameters, functions and `foreach` declarations can be `ref`".
Fair enough. I thought that the * and & operator was for when
interfacing with C/C++ code. Since this is entirely in D code, I
thought there might be other options.
```
import std.stdio;
void main()
{
struct S {
char c;
float f;
}
S*[int] aa; // hold pointers to the struct S instances
S *d;
S u;
S v;
u.c = 'a'; u.f = 1.33;
aa[0] = &u;
v.c = 'z'; v.f = 3.14;
aa[1] = &v;
d = aa[0];
writeln("d.c = ", d.c, " d.f = ", d.f);
d = null;
u.c = 'A'; u.f = 9.9;
d = aa[0];
writeln("d.c = ", d.c, " d.f = ", d.f);
}
```
More information about the Digitalmars-d-learn
mailing list