Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!samsung!uunet!brunix!sdm From: sdm@brunix (Scott Meyers) Newsgroups: comp.lang.c++ Subject: Re: Design Problem Message-ID: <22211@brunix.UUCP> Date: 5 Dec 89 01:49:10 GMT References: <22137@brunix.UUCP> <11258@csli.Stanford.EDU> Sender: news@brunix.UUCP Reply-To: sdm@norton.UUCP (Scott Meyers) Organization: Brown University Department of Computer Science Lines: 39 In article rich@Rice.edu (Carey R. Murphey) writes: >Would it be reasonable to set the virtual memeber function pointer >to NULL (0) by default to indicate there is no function defined by >default? Here's an idea of how that might work: > >class ARC >{ > virtual void execute() = 0; // there is no execute method by default. >} > >ARC an_arc; > >if (an_arc.execute) > an_arc.execute(); // execute the method if it exists. > >I dunno... I haven't actually tried this to see if it works. I think >libg++ uses this in it's `Bag' container classes. This is a good idea, and in fact it works with g++, but the AT&T compiler won't take it. (Actually, CC generates a warning -- "address of bound function" -- and then cc chokes.) I played around with this a bit, and it doesn't look like there's any obvious way to dynamically determine the address of a member function for a polymorphic object. That is, given a pointer to an object p and a virtual member function mf, there doesn't seem to be any way to get the address of p->mf. If anybody comes up with a way to do this, I'd like to hear about it! Scott sdm@cs.brown.edu S i g h S i g h