Class Field Size/Offsets

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Mar 2 14:49:58 PST 2013


On Saturday, 2 March 2013 at 22:10:57 UTC, Maxime Chevalier wrote:
> The problem persists without the mixin and the template:
>
> class C { int a; }
>
> struct Foo
> {
>     void foo()
>     {
>         auto sz = C.a.sizeof;
>         writefln("sz: %s", sz);
>     }
> }
>
> static this()
> {
>     Foo f;
>     f.foo();
> }
>
> Error: this for a needs to be type C not type Foo

For 2.062 you're going to have to move the .sizeof expression
outside of any methods which require 'this'. Make 'foo' static or
wrap the .sizeof expression inside of a template and it will
work. E.g.:

template getSizeOf(alias symb)
{
      enum getSizeOf = symb.sizeof;
}

struct Foo
{
      void foo()
      {
          auto sz = getSizeOf!(C.a);
          writefln("sz: %s", sz);
      }
}

It's just a bug which will be fixed in the next version.


More information about the Digitalmars-d mailing list