Pointer to member variable again
ws
wisiong at gmail.com
Mon Jul 28 22:33:51 PDT 2008
Maybe i should have written it this way:
int function() fp;
int delegate() dp;
int *ptr;
class Cls
{
int k;
int foo() { return k; }
}
void main()
{
fp = &Cls.foo;
assert(fp() == 0);
Cls c = new Cls;
dp = &c.foo;
ptr = &c.k;
assert(is(typeof(ptr) == int*));
assert(is(typeof(fp) == int function()));
assert(is(typeof(dp) == int delegate()));
}
Notice fp can be used without an instance of Cls.
What i need is actually a way to get the type of the class when i reference the variable k, without actually creating an instance of the class.
Something like this:
typedef GetClass!(Cls.k) classType;
assert(is(typeof(classtype) == class) && is(typeof(classtype) == Cls));
Is there a way to do it?
More information about the Digitalmars-d-learn
mailing list