Pointer to member variable again

Carl Clark carlclark at lavabit.com
Mon Jul 28 21:33:54 PDT 2008


Shouldn't this work?

//...
class Cls
{
   int k;
   static int foo() { return 0; }
}
//...

The deal is that int foo() by itself is an instance method, but static 
declares it a class method, which is what you want -- class methods are 
shared, so you can simply call (or dereference) them without instances.

On 2008-07-28 19:45, ws spoke thusly:
> 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!


More information about the Digitalmars-d-learn mailing list