www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Abstract override behaviour

reply Claudiu <clau_sav yahoo.com> writes:
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
Feb 05 2020
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 2/5/20 8:49 AM, Claudiu wrote:

 In class "Min" definition I am receiving this error: "cannot implicitly 
 override base class method `IncrementalStat.accumulate` with  
 `Min.accumulate`; add `override` attribute"
Andrei's book is a little dated. Here is the errata: http://erdani.com/index.php?cID=109 Ali
Feb 05 2020
parent reply Claudiu <clau_sav yahoo.com> writes:
On Wednesday, 5 February 2020 at 16:55:42 UTC, Ali Çehreli wrote:
 On 2/5/20 8:49 AM, Claudiu wrote:

 In class "Min" definition I am receiving this error: "cannot 
 implicitly override base class method 
 `IncrementalStat.accumulate` with  `Min.accumulate`; add 
 `override` attribute"
Andrei's book is a little dated. Here is the errata: http://erdani.com/index.php?cID=109 Ali
Thanks a lot, I'll need to keep this errata close for future "surprises". I'm trying to learn idiomatic D. I think that this book is still relevant, but are there other recommended books?
Feb 05 2020
parent Paul Backus <snarwin gmail.com> writes:
On Wednesday, 5 February 2020 at 17:11:28 UTC, Claudiu wrote:
 Thanks a lot, I'll need to keep this errata close for future 
 "surprises". I'm trying to learn idiomatic D. I think that this 
 book is still relevant, but are there other recommended books?
https://p0nce.github.io/d-idioms/#Which-book-should-I-read?
Feb 05 2020