Alternative:
import std.stdio;
struct S {
uint longnamed;
alias longnamed this;
}
void main() {
S somestruct;
alias v = somestruct;
writeln(v);
v++;
writeln(v);
}
Oh, it doesn't work when accessing member data. Sorry for the
noise.
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 ?
I'd say this is some
You don't need to use dereference operator. Example:
http://dpaste.dzfl.pl/d34c23e5
import std.stdio;
struct Foo {
void answer() {
writeln("As you wish!");
}
}
void main() {
Foo veryVeryLongNamedStruct;
auto v = &veryVeryLongNamedStruct;
v.answer();
}
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
On Monday, 29 July 2013 at 21:37:30 UTC, bearophile wrote:
Temtaime:
Why i cannot declare reference in D ?
I don't know the reasons. But maybe you can create a little
struct with just a pointer inside and an alias this to a member
function that returns a ref.
Bye,
bearophile
It doesn't
Temtaime:
I have a long named variable in a struct.
For example let's name that longnamedstruct.longnamedmember
I need to use that variable in many places of the code and i
cannot create the copy of it.
You can shorten the outer name with an alias or "remove" it with
a with() statement.
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 ?
On Monday, 29 July 2013 at 21:13:54 UTC, Temtaime wrote:
I have a long named variable in a struct.
For example let's name that longnamedstruct.longnamedmember
I need to use that variable in many places of the code and i
cannot create the copy of it.
In c++ i can
auto &v = longnamedstruct.lon
I have a long named variable in a struct.
For example let's name that longnamedstruct.longnamedmember
I need to use that variable in many places of the code and i
cannot create the copy of it.
In c++ i can
auto &v = longnamedstruct.longnamedmember;
Now i can use v anywhere.
Why i cannot decl
10 matches
Mail list logo