Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!pdn!tscs!tct!chip From: chip@tct.com (Chip Salzenberg) Newsgroups: comp.std.c++ Subject: Re: Objects already contain type information => binary virtual functions Message-ID: <27F63CE7.D89@tct.com> Date: 31 Mar 91 19:47:51 GMT References: Organization: Teltronics/TCT, Sarasota, FL Lines: 33 According to ngo@tammy.harvard.edu (Tom Ngo): >The problem: > > class B { > virtual void foo(B*); > }; > class D : public B { > virtual void foo(D*); > }; > > void bar(B* b1, B* b2) { > b1.foo(b2); > } > > D d1; > D d2; > bar(&d1,&d2); // I want D::foo to be invoked To suppose that D::foo() should override B::foo() is to misunderstand the meaning of virtual functions, namely: A virtual function is _one_ function with potentially many implementations. The code quoted above shows that D::foo() is prepared to work on a D, while B::foo() is prepared only for a B. Thus they are not the same function. They may be equivalent in one way or another; they may even have the same body. But they are not the _same_ function. So the use of "virtual" for these two functions is a design error. -- Chip Salzenberg at Teltronics/TCT , "All this is conjecture of course, since I *only* post in the nude. Nothing comes between me and my t.b. Nothing." -- Bill Coderre