Semantics of @disable
bearophile
bearophileHUGS at lycos.com
Mon Apr 19 05:12:12 PDT 2010
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
More information about the Digitalmars-d-learn
mailing list