Declare reference to variable ?
Namespace
rswhite4 at googlemail.com
Mon Jul 29 21:55:15 PDT 2013
On Monday, 29 July 2013 at 21:25:21 UTC, Temtaime wrote:
> No, i cannot.
>
> struct S {
> uint longnamed;
> }
>
> void main() {
> S somestruct;
>
> alias v = somestruct.longnamed;
> writeln(v);
> }
>
> Error: need 'this' for 'longnamed' of type 'uint'
>
> Is it a bug ?
Oh, that is annoying...
Then, make your own reference type:
import std.stdio;
struct S {
uint longnamed;
}
struct Ref(T) {
public:
T* ptr;
@disable
this();
/*@disable
this(this);*/
@disable
this(typeof(null));
@disable
void opAssign(ref Ref!T);
this(T* ptr) {
this.ptr = ptr;
}
@property
ref inout(T) get() inout {
return *this.ptr;
}
alias get this;
}
void main() {
S somestruct;
Ref!uint v = &somestruct.longnamed;
writeln(v);
}
More information about the Digitalmars-d-learn
mailing list