Re: Abstract classes
TBass <tbj@automateddesign.com> wrote in
news:1194623498.030072.297440@i38g2000prf.googlegroups.com:
On Nov 9, 9:48 am, Brian Szmyd <brian.sz...@gmail.com> wrote:
Where are:
virtual bool InRect(double x, double y); virtual bool
OnLButtonDown(double x, double y); virtual bool
OnLButtonUp(double x, double y); virtual bool
OnRButtonDown(double x, double y); virtual bool
OnRButtonUp(double x, double y);
Implemented? You've made them pure virtual in your parent class, but
I don't see the child class implementation of them. You can't
instantiate an object of a class that has any pure virtual methods
(inherited or not).
Ah! I thought I could pick and choose which virtual functions I wanted
to implement.
Thanks!
TBJ
No... Any method declared in a class must be implemented somewhere.
The 'where' is what changes between pure virtuals, virtuals, and non-
virtuals. With pure virtuals, the method is guaranteed to be
implemented in a derived class. With virtuals, an implementation must
be available in the base class, but it can be overridden in the derived
classes. And, finally with non-virtuals, the implementation must be in
the base class and can't be overridden by a child. (Note, it can be
hidden be a new implementation in the child, but it is a bad idea.)
The class declaration is your contract with your user as to what
services your object provides. Rarely is faulting out an acceptible
response to an attempt to use a service.
joe