🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Wil Evers Thu, 22 Feb 1996 17:15
Re: Legal C++ code?
#3403
Author: 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 
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads