Pointer to member variable again
Steven Schveighoffer
schveiguy at yahoo.com
Tue Jul 29 07:22:25 PDT 2008
"ws" wrote
> Suppose i have the following:
>
> int function() fp;
> int *ptr;
> class Cls
> {
> int k;
> int foo() { return 0; }
> }
>
> void main()
> {
> fp = &Cls.foo;
>
> Cls c = new Cls;
> ptr = &c.k; // <-- why always need a new instance?
> }
>
> As compared to delegate, is there no analogous way to specify this?
>
> ptr = &Cls.k
>
> Thanks!
In fact, this should fail to compile. The fact that it succeeds is a bug.
You should enter it in bugzilla (is it already there?)
Did you try running it? I get a segfault.
fp is a member function, which means it needs a hidden 'this' pointer. When
you assign &Cls.foo to fp, this should result in the same error as if you
typed Cls.foo():
Error: need 'this' to access member foo
-Steve
More information about the Digitalmars-d-learn
mailing list