mixin template and const property qualifier?

aldanor via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 15 15:14:28 PST 2014


Could someone please explain why the following doesn't compile 
with "const" qualifier while it does work without it?

/* test.d */

module test;

mixin template Foo() {
     mixin("@property int bar() const { return foo; }");
}

int foo = 1;

mixin Foo;

unittest {
     assert(foo == bar);
}

> rdmd -main -unittest test.d
test.d-mixin-4(4): Error: function test.Foo!().bar without 'this' 
cannot be const
test.d(9): Error: mixin test.Foo!() error instantiating


More information about the Digitalmars-d-learn mailing list