On 10/29/2012 2:28 PM, Jesse Phillips wrote:
> On Sunday, 28 October 2012 at 13:39:26 UTC, bearophile wrote:
>> 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() {}
>
> Interestingly, adding abstract to the method will result in no linker error 
for
> compiling.

That's because by saying "abstract" you're telling the compiler that there is no implementation for A.foo(), which is fundamentally different from saying that A.foo() is defined elsewhere. The compiler inserts a 0 in the vtbl[] slot for it, even though it won't let you try to call it.

> And if a new B is created then a compiler error is provided instead
> of a linker error.

Abstract types are really a different thing from "it's defined somewhere else."

> I'm for getting some line numbers over the less informative linker error.

The object file format does not support line numbers for symbol references and definitions. None of the 4 supported ones (OMF, ELF, Mach-O, MsCoff) have that. Even the symbolic debug info doesn't have line numbers for references, just for definitions.

Reply via email to