www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Inheritance hierachy: Class from Abstract class from Interfaces, does

reply zack <no-way-zack no-web.de> writes:
Sorry for the weird title.
I dealt with interfaces and abstract classes and came accross a 
behavior I didn't expect. Can someone clarify if this behavior is 
wanted?

I have multiple interfaces, were an abstract class inherits from. 
The abstract class however, just defines part of the functions to 
be abstract and does not implement the others. A concrete class 
then finally derives from the abstract class.

So I as a user would expect that the concrete class implements 
all methods defined in the interfaces. However, this seems to not 
be the case. The following code compiles just fine, even if baz() 
was never implemented. Calling the baz() function on a Concrete 
object causes the program to crash.

interface A {
	void foo();
}

interface B {
	void baz();
}

class Abstract : A, B {
	abstract void foo();
}

class Concrete : Abstract {
	override void foo()	{ writeln("foo"); }
}
Mar 24 2021
parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Wednesday, 24 March 2021 at 08:22:51 UTC, zack wrote:
 Sorry for the weird title.
 I dealt with interfaces and abstract classes and came accross a 
 behavior I didn't expect. Can someone clarify if this behavior 
 is wanted?

 [...]
that is possibly https://issues.dlang.org/show_bug.cgi?id=19192 which has a PR https://github.com/dlang/dmd/pull/12302 in review, which should be merged very soon.
Mar 24 2021