Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!wuarchive!m.cs.uiuc.edu!ibma0.cs.uiuc.edu!ux1.cso.uiuc.edu!usenet From: dmmg1176@uxa.cso.uiuc.edu (David M Marcovitz) Newsgroups: comp.sys.mac.programmer Subject: Think C polymorphism problem Message-ID: <1991Mar6.233602.27014@ux1.cso.uiuc.edu> Date: 6 Mar 91 23:36:02 GMT Sender: usenet@ux1.cso.uiuc.edu (News) Organization: University of Illinois at Urbana Lines: 39 I am using Think C 4.0 with TCL. I have a superclass CFoo with subclasses CBar and CBaz. CFoo has the following methods: void CFoo::MyMainMethod() { TheAuxMethod(); /* Call an auxiliary method in CBar or CBaz */ } void CFoo::TheAuxMethod() { /* This is to be overridden by CBar and CBaz */ } ------------------------------------ CBar and CBaz have the following method: void CBar::TheAuxMethod() /*substitute CBaz for CBar in CBaz.c*/ { /* Insert stuff that should get done. */ } ------------------------------------ When MyMainMethod is running (a method of CFoo), it calls TheAuxMethod. I don't want CFoo to have to know if the real object is a CBar or CBaz object (i.e., I don't want some if structure to check if I am a CBar and call CBar::TheAuxMethod or CBaz::TheAuxMethod). I thought that by calling TheAuxMethod, the correct TheAuxMethod (from the subclass, CBar or CBaz) would run. That is not happening. The CFoo TheAuxMethod is getting called; it is not being overriden. How can I call TheAuxMethod from one of CFoo's methods and have it be overridden by CBar or CBaz's TheAuxMethod? -- David M. Marcovitz | internet: marcovitz@uiuc.edu Computer-based Education Research Lab | dmmg1176@uxa.cso.uiuc.edu University of Illinois | novanet: marco / cca / cerl