Pointer to member variable again
ws
wisiong at gmail.com
Tue Jul 29 19:39:30 PDT 2008
Simen Kjaeraas Wrote:
> 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
Sorry the fp has to be called after Cls is instanstiated. Fixed as below:
fp = &Cls.foo;
Cls c = new Cls;
assert(fp() == 0); <-- after Cls instantiation.
More information about the Digitalmars-d-learn
mailing list