Your example works but my use case doesn't and I have no idea why:

class C { int a; }

struct Foo
{
    void foo(string className, string fieldName)()
    {
mixin("auto sz = " ~ className ~ "." ~ fieldName ~ ".sizeof;");

        writefln("sz: %s", sz);
    }
}

static this()
{
    Foo f;

    f.foo!("C", "a");
}

Produces:

Error: this for a needs to be type C not type Foo
Error: template instance Foo.foo!("C", "a") error instantiating

Reply via email to