Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!zaphod.mps.ohio-state.edu!wuarchive!uunet!bywater!arnor!watson!blinn.watson.ibm.com!mittle From: mittle@blinn.watson.ibm.com (Josh Mittleman) Newsgroups: comp.lang.c++ Subject: Re: Calling Parent functions in Child??? - not always .. Message-ID: <1991May17.142431.13719@watson.ibm.com> Date: 17 May 91 14:24:31 GMT References: <91132.113932ACPS2924@Ryerson.Ca> <1991May15.044458.21518@minyos.xx.rmit.oz.au> <3022@moth.sw.mcc.com> Sender: @watson.ibm.com Organization: IBM T. J. Watson Research Lines: 75 In article <3022@moth.sw.mcc.com>, rcp@moth.sw.mcc.com (Rob Pettengill) writes: > > B::isEqual() > > { > > return (... && A:isEqual() ); > > }; > 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. > > class MetricWeightMixin : { > public: > virtual float weight(); > } > > MetricWeightMixin::weight() > { > return lbsToKilos( DontKnowWhatClassToPutHere::weight()); > } True, the method first described won't work, but that's because you are dealing with an entirely different situation. The original post wanted to know how to explicitly access a base class member: Your MetricWeightMixin has no base class. If I understand correctly, you are doing something like this: MetricWeightMixin AnyClass which defines float weight, and returns \ weights in pounds \ / Subclass which is identical to AnyClass, but its weight() returns kilograms. To be frank, I can't see any way to make this work. The problem is that you aren't abstracting the property of weightedness properly. I would define an abstract class WeightedObject, two subclasses MetricWeightedObject and EnglishWeightedObject, and then derive more useful classes from one or the other of these: class WeightedObject { protected: virtual float pounds() = 0; // returns weight in pounds. This is // used as an internal function, // to provide a standard "base" weight. virtual float kilos() { return lbsToKilos(pounds()); } float lbsToKilos(const float); float kilosToLbs(const float); // Note that in this case, I've assumed that a derived class will // first compute its weight in pounds, and then will be able to // convert that to kilos. Obviously, any particular derived class // could re-implement these functions to do the opposite. public: virtual float weight() = 0; }; class MetricWeightedObject { public: float weight() { return kilos(); } }; class EnglishWeightedObject { public: float weight() { return pounds(); } }; =========================================================================== Josh Mittleman (mittle@watson.ibm.com or joshua@paul.rutgers.edu) J2-C28 T.J. Watson Research Center, PO Box 704, Yorktown Heights, NY 10598