April 19, 2010 Semantics of @disable | ||||
---|---|---|---|---|
| ||||
Is this how @disable is supposed to work (D2 code)? Is overriding a disabled function meaningful? import std.c.stdio: puts; class A { void foo() { puts("A.foo()"); } } class B : A { //@disable override void foo(); // Linker error @disable override void foo() { puts("B.foo()"); }; // OK } class C : B { override void foo() { puts("C.foo()"); }; } void main() { A b = new B; b.foo(); // OK, Output: B.foo() B b2 = cast(B)b; // Compile-time Output: Error: function test.B.foo is not callable because it is annotated with @disable b2.foo(); C c = new C; c.foo(); // OK, Output: C.foo() } Bye and thank you, bearophile |
Copyright © 1999-2021 by the D Language Foundation