Why do abstract class functions require definitions?

FiveNights via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Sep 16 01:49:19 PDT 2015


Every so often I'll get a compiler error that isn't particularly 
clear on what's wrong and eventually I'll figure out that what's 
causing it is having a function in an abstract class somewhere 
that isn't defined:

abstract class SomeClass {
     int someVariable;
     void someFunction();
}
the solution is usually:
void someFunction(){}

Usually the abstract class is a converted interface, but it 
turned out that I needed to include a variable for it to work out 
and I just wasn't keen on remembering to put a mixin in each 
derived class.

I'm just wondering why I can't have an undefined function in an 
abstract class? I'd the compiler to say, "Hey, you forgot to put 
'someFunction()' in 'SomeDerrivedClass', go do something about 
that." when I end a function with a semi-colon in the base class 
and don't have it in the derrived. Everything just seems to break 
in cryptic ways unless I curly brace the function ending.


More information about the Digitalmars-d-learn mailing list