On 04/26/2012 04:43 AM, Victor Vicente de Carvalho wrote:
Hi there,
In c++ one can access a pointer to a class/struct variable using this
semantic:
struct C {
int x;
};
int C::* ptr = C::x;
C foo;
foo.*ptr = 10;
assert(foo.x == 10);
It is possible to do something like that on D? I've
This is the closest thing:
---
struct C {
int x;
int* ptr() @property { return x; }
}
C foo;
*foo.ptr = 10;
assert(foo.x = 10);
---
Now you can also do:
struct C
{
int x;
}
int* ptr() @property { return x; }
C foo;
*foo.ptr = 10;
assert(foo.x = 10);
if you can't or don't want to
Now you can also do:
struct C
{
int x;
}
int* ptr() @property { return x; }
C foo;
*foo.ptr = 10;
assert(foo.x = 10);
if you can't or don't want to change C.
int* ptr() @property { return x; }
should be
int* ptr(ref C c) @property { return c.x; }
Hi there,
In c++ one can access a pointer to a class/struct variable using
this semantic:
struct C {
int x;
};
int C::* ptr = C::x;
C foo;
foo.*ptr = 10;
assert(foo.x == 10);
It is possible to do something like that on D? I've searched
through the forum documentation but didn't found
On Thursday, 26 April 2012 at 02:43:35 UTC, Victor Vicente de
Carvalho wrote:
Hi there,
In c++ one can access a pointer to a class/struct variable
using this semantic:
struct C {
int x;
};
int C::* ptr = C::x;
C foo;
foo.*ptr = 10;
assert(foo.x == 10);
It is possible to do something
On Thursday, 26 April 2012 at 03:54:25 UTC, Nathan M. Swan wrote:
Yes. My rule: don't use pointers unless doing it otherwise is
really slow or really hard.
Might be safe to use a pointer on an immutable struct (Say,
globally accessible data?). I'm trying this; but it's only to get
around
On Thu, Apr 26, 2012 at 06:57:50AM +0200, EraScarecrow wrote:
On Thursday, 26 April 2012 at 03:54:25 UTC, Nathan M. Swan wrote:
Yes. My rule: don't use pointers unless doing it otherwise is
really slow or really hard.
Might be safe to use a pointer on an immutable struct (Say,
globally
On Thursday, 26 April 2012 at 05:16:51 UTC, H. S. Teoh wrote:
Besides, D's auto-deferencing semantics on pointers
makes the difference barely noticeable anyway. Pointers
auto-deference when using '.' member notation, for example. Once
in a while you have to explicitly dereference a pointer or