Overloading/Inheritance issue
Sean Kelly
sean at f4.ca
Fri Aug 3 23:08:11 PDT 2007
Walter Bright wrote:
> Sean Kelly wrote:
>> Walter Bright wrote:
>>> I agree that this example is a problem. There's no way to detect it
>>> at compile time, so it should throw a runtime exception. The way to
>>> accomplish that is to stuff D's vtbl[] entry for B.set(int) with a
>>> dummy function that throws the exception.
>>
>> Certain C++ compilers have done something like this in the past, if I
>> remember correctly. I'd have to do some googling to remember the
>> details, but I'm sure it was either the MS or Sun compiler.
>
> I didn't know that. This particular problem may not come up so often
> with C++ because functions are not virtual by default - but not virtual
> by default produces its own set of very hard to find bugs that I've
> wasted many hours tracking down.
I stumbled across the information while trying to diagnose a bizarre
linker error. It turned out that the function that couldn't be found
was the dummy routine. And that reminds me which compiler it is--it's
the MS one. Their explanation made it seem like the situation the
routine was there for wasn't likely to ever actually happen and I
regarded it as a curiosity at the time. It's kind of neat to see the
idea resurface here though :-)
Sean
More information about the Digitalmars-d
mailing list