Re: On inheritance and polymorphism in cats and dogs (and other beasts too)

2014-12-21 Thread Mike Parker via Digitalmars-d-learn
On 12/22/2014 1:11 AM, Derix wrote: Yep, I rekon the difference was not clear to me. It still isn't right now, but at least now I know that it exists and I have to look into it. Overriding - a subclass reimplements a method from a base class. The method must have the same number and type of p

Re: On inheritance and polymorphism in cats and dogs (and other beasts too)

2014-12-21 Thread Derix via Digitalmars-d-learn
Thanks a lot, I begin to see the light ! you aren't overriding anything -- you are /overloading/ Yep, I rekon the difference was not clear to me. It still isn't right now, but at least now I know that it exists and I have to look into it. As to the spell you cast to my cats in your rewriting

Re: On inheritance and polymorphism in cats and dogs (and other beasts too)

2014-12-21 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 21 December 2014 at 15:05:47 UTC, Mike Parker wrote: // Now do Catty things pickiness = (mother.pickiness + father.pickiness) / 2; Sorry, forgot to change that line when I copy-pasted. Should be: pickiness = (catmom.pickiness + catdad.pickiness) / 2;

Re: On inheritance and polymorphism in cats and dogs (and other beasts too)

2014-12-21 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 21 December 2014 at 10:42:37 UTC, Derix wrote: If you change the mother and father parameters from Beasts to Cats, then you aren't overriding anything -- you are /overloading/. That's where the first two errors were coming from. In order for a subclass method to override a base cl

Re: On inheritance and polymorphism in cats and dogs (and other beasts too)

2014-12-21 Thread Derix via Digitalmars-d-learn
Thank you kindly for this detailed response. Your directions bore frution, and I now have cats that breed cats (and not dogs). However I can't get rid of the following warning on compilation : |... | void mixGenetics(Cat mother,Cat father) {...} |... Warning: Beast.Beast.mixGenetics(Beast mother

Re: On inheritance and polymorphism in cats and dogs (and other beasts too)

2014-12-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 20 December 2014 at 15:40:32 UTC, Derix wrote: // do what all beasts do You'll want to call the function in the base class, which is done with the super keyword in D. I wouldn't make the super function return the new instance though, that can't be as easily cust

Re: On inheritance and polymorphism in cats and dogs (and other beasts too)

2014-12-20 Thread tcak via Digitalmars-d-learn
On Saturday, 20 December 2014 at 15:40:32 UTC, Derix wrote: So, I have this pet project where classes Cat and Dog inherit from the more generic Beast class. All beasts prosper and multiply and so do cats and dogs. The breeding routine is fairly constant across species, with minor variations. So

On inheritance and polymorphism in cats and dogs (and other beasts too)

2014-12-20 Thread Derix via Digitalmars-d-learn
So, I have this pet project where classes Cat and Dog inherit from the more generic Beast class. All beasts prosper and multiply and so do cats and dogs. The breeding routine is fairly constant across species, with minor variations. So I'd like to define the "breed" method in the Beast class and