Abstract override behaviour

Claudiu clau_sav at yahoo.com
Wed Feb 5 16:49:18 UTC 2020


Hi dlang community,

Just started to learn D using Visual Studio 2007, latest VisualD 
(VisualD-v0.51.0-dmd-2.090.0-ldc2-1.19.0) and "The D Programming 
Language" by Andrei Alexandrescu.

I am trying to run most of the examples and had a surprise at 
chapter 1.6.1 "More Statistics. Inheritance" with the following 
code:

interface Stat {
     void accumulate(double x);
     ...
}

class IncrementalStat : Stat {
     ...
     abstract void accumulate(double x);
     ...
}

class Min : IncrementalStat {
     ...
     void accumulate(double x) { ... }
     ...
}

In class "Min" definition I am receiving this error: "cannot 
implicitly override base class method 
`IncrementalStat.accumulate` with  `Min.accumulate`; add 
`override` attribute"

After I update "Min" class to << override void accumulate(double 
x) >> everything works fine.
Can anybody clarify where is the problem.

Thanks in advance,
Claudiu



More information about the Digitalmars-d-learn mailing list