🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3403

Re: Legal C++ code?

#3403
From: Wil Evers
Date: Thu, 22 Feb 1996 17:15
35 lines
2172 bytes
In article <4gbilr$38m@dub-news-svc-1.compuserve.com> 71247.3221@compuserve.com (Don Wallace) writes:

[example of derived class calling pure virtual function in base class]
 
> I suspect that this is perfectly legal C++ code. Every statement taken
> individually is correct. But even if it linked, the net effect of
> calling bar.foo() would be to attempt to activate a pure virtual
> function (In Borland C++ this generates a RTL program halt - it says
> 'pure virtual function called'.)
> 
> The statement/function 
> 
> >    int foo() { return Foo::foo(); }
> 
> refers to Foo::foo() which is inherently not defined. Hence the link
> error.

This is a common misconception: a pure virtual function may or may
not have a definition. It it doesn't have a definition and you try to 
call it anyway, you will probably get a link-time- or run-time error or
your program could just go haywire; if it does have a definition, then
calling it is perfectly OK. The canonical example of a pure virtual
function that does have a definition is a pure virtual destructor: 
without a body, such a class would not be very useful.

- Wil

Wil Evers, ITT Publitec Research and Development, <wil@ittpub.nl>
---
[ To submit articles: Try just posting with your newsreader.  If that fails,
                      use mailto:std-c++@ncar.ucar.edu
  FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <0099E49564818440.3D607462@ittpub.nl>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: "Wil Evers" <wil@ittpub.nl>
Newsgroups: comp.std.c++
Subject: Re: Legal C++ code?
Date: 22 Feb 1996 09:15:03 PST
Organization: -
Approved: austern@isolde.mti.sgi.com
Message-ID: <0099E49564818440.3D607462@ittpub.nl>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: Thu, 22 Feb 96 10:02:52 WET
X-Vms-Mail-To: IN%"std-c++@ncar.ucar.edu"
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMSykpky4NqrwXLNJAQExJwH+O9X0B6B+rqof8wPov/g/LW21D5sPHT5e
 Osi+PKjEvg/2+6+jRqUB0p9eIR+k3FpvQtBjE/5HqvwwVYLE+5dQOQ==
 =aGQn
Originator: austern@isolde.mti.sgi.com