To avoid some linking errors
bearophile
bearophileHUGS at lycos.com
Sun Oct 28 06:39:24 PDT 2012
This code compiles with no errors, and then later the linker
gives a "Symbol Undefined":
abstract class A {
public void foo();
}
class B : A {}
void main() {}
In this bug report I have asked for the compiler to give an error:
http://d.puremagic.com/issues/show_bug.cgi?id=5129
But Walter has answered it's not a bug:
> This is not a bug, as in another module there could be a class
> C that derives
> from B and implements foo().
>
> As documented, D accepts non-abstract functions with no body
> declared as:
>
> void foo();
>
> with the idea that the user will be supplying a body somewhere
> else - perhaps
> even a C function or an assembler one. It's another way of
> doing encapsulation
> by having an opaque implementation. In fact, it's used by the
> TypeInfo's.
Stewart Gordon suggests:
> I think the underlying problem is that there's no mandatory
> explicit notation
> for externally defined functions.
So isn't it better to require (similarly to annotations like
"override") the programmer to write in B an "extern" or
"abstract" or something similar to state that the implementation
is elsewhere (and give a nice compilation error if it's missing)?
abstract class A {
public void foo();
}
class B : A {
extern foo;
}
void main() {}
Or:
abstract class A {
public void foo();
}
class B : A {
abstract foo;
}
void main() {}
Bye,
bearophile
More information about the Digitalmars-d
mailing list