Path: utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: virtual and overloading Message-ID: <10606@alice.UUCP> Date: 21 Mar 90 13:54:39 GMT References: <58.UUL1.3#5109@pantor.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 59 In article <58.UUL1.3#5109@pantor.UUCP>, richard@pantor.UUCP (Richard Sargent) writes: > We have a derived tree of classes of graphical objects, with the > base class defining a 'virtual void draw( some *obj )'. In one > derived class, a way down the tree of classes, we have a class > in which we want to have a function 'void draw( void )'. That is, > we want a function for that particular class which takes no > argument. > Attempting to do this the obvious way results in a type mismatch. If you do something like this: class Base { public: virtual void draw(some*); }; class Derived: public Base { public: virtual void draw(); }; you haven't exactly done anything wrong, but you probably didn't do what you expected. Unless the argument types match exactly in the base and derived classes, you have defined two totally different functions. That is, if you say Base* bp = new Derived; bp->draw(); the compiler will complain because Base::draw(void) isn't defined. If instead you say bp->draw(sp); where `sp' is a some*, that's fine -- but you will call Base::draw(some*) and not Defined::draw(void). > Q: is it necessary that the base class define 'virtual void draw( void )' > to overload it, even though the only class to use it is way down > the tree of classes? > If we do this then we get an error message on the derived classes > which define 'void draw( some *obj )', namely "sorry, not implemented: > virtual derclass::draw() overloaded in base class but not in derived > class". So, does this mean that we have to specify the overloading > of the 'void draw( void )' in all derived classes? If you are really getting a `sorry not implemented' message instead of a warning, that strongly suggests that you are not doing exactly what you illustrated here. Perhaps you could post a complete example? Preferably a small one. -- --Andrew Koenig ark@europa.att.com