Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!sun-barr!cs.utexas.edu!uunet!mcvax!unido!iraun1!iravcl!s_heising From: s_heising@iravcl.ira.uka.de Newsgroups: comp.lang.c++ Subject: RE:Return types of virtual member functions Message-ID: <297@iravcl.ira.uka.de> Date: 1 Jun 89 15:02:02 GMT Lines: 42 Organisation: Universitaet Karlsruhe, IRA, F.R. Germany In his article <3403@hplabsz.HPL.HP.COM> bs@hplabsz.HPL.HP.COM (Bob Shaw) writes about his problems with return types of virtual member functions. void main() { parent* presult; child* cresult; parent* p = new parent; child* c = new child; presult = p->msg(); <-- expectation correct cresult = c->msg(); <-- expectation correct p = c; <-- misunderstanding! change in value, not in type presult = p->msg(); <-- still calls parent::msg not child::msg as expected } I'm not an experienced C++ or C-programmer, my interest is theoretically rather. But I think the solution to the problem is as follows: Bob is mixing up assigning values and declaring types. to be more concrete, that part of c's value p can hold. It doesn't makes p to become an object of class child, of class parent, not the one of class child. Bye!