Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!rice!brazos!rich From: rich@Rice.edu (Carey R. Murphey) Newsgroups: comp.lang.c++ Subject: Re: Design Problem Message-ID: Date: 4 Dec 89 20:41:21 GMT References: <22137@brunix.UUCP> <11258@csli.Stanford.EDU> Sender: root@rice.edu Organization: Department of Electrical and Computer Engineering, Rice University Lines: 36 In-reply-to: keith@csli.Stanford.EDU's message of 4 Dec 89 17:25:40 GMT In article <11258@csli.Stanford.EDU> keith@csli.Stanford.EDU (Keith Nishihara) writes: >What I really want to be able to say is "if function f() is defined for >object o, then call o.f()". Is there a good way to acheive this effect? It seems to me that the virtual function defined on ARC with no ops for non executable arcs is what you need. However, one other approach which might be considered if you have lots of functions like execute, and especially if the functions applicable to executable arcs are from an open ended set, is as below: [code followed...] 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. -- Rich@rice.edu