Overriding interface method without implementation
Uranuz
neuranuz at gmail.com
Sun Nov 17 10:33:53 PST 2013
Sometimes when I build my code I get error message(s) starting
with `undefined reference to`. Because it happens not too often
it's not obvious and easy to understand what is the problem.
There is an easy example:
import std.stdio;
interface I
{
void foo(int num);
int bar();
}
class A: I
{
override {
void foo(int num); //This string is evil root))
int bar()
{ return 100; }
}
}
void main()
{
writeln("Hello, world!!!");
}
Compilation output:
/d621/f189.o:(.rodata+0x138): undefined reference to
`_D4f1891A3fooMFiZv'
/d621/f189.o: In function `_TMP3':
/d621/f189.d:(.text._D4f1891A3barMFZi+0x55): undefined reference
to `_D4f1891A3fooMFiZv'
collect2: error: ld returned 1 exit status
--- errorlevel 1
It happens because after invention of some interface I simply
copy-paste its contents into class A that implements I. And
sometimes I can forget to implement some small function that for
example just returns value of some field.
In such cases I will get some not very obvious error that can't
help me to find out module name and line index that produces this
error.
As far as I know this syntax for function without implementation
mean that it will be implemented somewhere else for example in C
code. But I think that for "usual" programmer some understandable
error message or warning is needed.
More information about the Digitalmars-d
mailing list