Why this UDP will not compile?

d coder via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 27 06:49:28 PDT 2014


DMD wont compile this. I get an error saying:
/tmp/test.d(3): Error: need 'this' for 'foo' of type 'int'
Failed: ["dmd", "-v", "-o-", "/tmp/test.d", "-I/tmp"]

Is this a bug or is it illegal code?

// Regards
// Cherry

class Foo {
  int foo = 42;
  @foo int bar;
  this(int frop) {
    foo = frop;
  }
  int getFooAttr() {
    auto ffff = __traits(getAttributes, this.tupleof[1]);
    return ffff[0];
  }
}

void main() {
  Foo f = new Foo(43);
  f.getFooAttr();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140927/b786349f/attachment.html>


More information about the Digitalmars-d mailing list