Article View: comp.std.c++
Article #999Re: Objects already contain type information => binary virtual functions
From: Chip Salzenberg
Date: Sun, 31 Mar 1991 19:47
Date: Sun, 31 Mar 1991 19:47
33 lines
1560 bytes
1560 bytes
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 <chip@tct.com>, <uunet!pdn!tct!chip>
"All this is conjecture of course, since I *only* post in the nude.
Nothing comes between me and my t.b. Nothing." -- Bill Coderre
Technical Details
Message-ID:
<27F63CE7.D89@tct.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!pdn!tscs!tct!chipReferences:
<NGO.91Mar28093648@tammy.harvard.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <NGO.91Mar28093648@tammy.harvard.edu> Organization: Teltronics/TCT, Sarasota, FL Lines: 33