Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!milano!moth.sw.mcc.com!rcp From: rcp@moth.sw.mcc.com (Rob Pettengill) Newsgroups: comp.lang.c++ Subject: Re: Calling Parent functions in Child??? - not always .. Message-ID: <3022@moth.sw.mcc.com> Date: 15 May 91 16:21:54 GMT References: <91132.113932ACPS2924@Ryerson.Ca> <1991May15.044458.21518@minyos.xx.rmit.oz.au> Reply-To: rcp@moth.sw.mcc.com (Rob Pettengill) Organization: MCC, Austin, Texas Lines: 62 In article <1991May15.044458.21518@minyos.xx.rmit.oz.au> s892992@minyos.xx.rmit.oz.au (Bossman) writes: ;ACPS2924@Ryerson.Ca writes: ; ;>If one has the following situation : ; ;>class A { int isEqual{}; } ; ;>class B : public A { int isEqual{} } ; ;>B::isEqual() ;>{ ;> return (... && // here i want to call the parents isEqual ;> // how do i do it?? ;>} ; ; Inside the isEqual member function of B, a call to isEqual will result in ;a recursive call back to the same member funcion. To call A's version of ;isEqual, you need to use scope resolution. You can do this as follows: ; ;B::isEqual() ;{ ; return (... && A:isEqual() ); ;} ; ;Simple huh! In fact the call to B's isEqual() member function can be structured ;the same way (ie: B::isEqual() ), but it is implicit that you are calling B's ;member functions from within a member of B. ; ;See ya, ; Kendall Bennett. This technique does not work for "mixin" style classes with multiple inheritance. A mixin class is designed to augment any of a number of possible parent classes. Mixins that add completely new functionality will work in c++. However mixins that seek to augment existing member functions run into the following difficulty. For an over simplified examaple - one might want to write a MetricWeightMixin that could be added to any class that returned an English Weight. class MetricWeightMixin : { public: virtual float weight(); } MetricWeightMixin::weight() { return lbsToKilos( DontKnowWhatClassToPutHere::weight()); } ;rob -- Robert C. Pettengill, MCC Software Technology Program P. O. Box 200195, Austin, Texas 78720, +1 512 338-3533 INTERNET: rcp@mcc.com UUCP: ..!cs.utexas.edu!milano!rcp -- Robert C. Pettengill, MCC Software Technology Program P. O. Box 200195, Austin, Texas 78720, +1 512 338-3533 INTERNET: rcp@mcc.com UUCP: ..!cs.utexas.edu!milano!rcp