Pointer to member variable again

Simen Kjaeraas simen.kjaras at gmail.com
Tue Jul 29 05:23:45 PDT 2008


On Tue, 29 Jul 2008 07:33:51 +0200, ws <wisiong at gmail.com> wrote:

> 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?

Have you tried calling fp in that example?

-- 
Simen


More information about the Digitalmars-d-learn mailing list