Article View: comp.std.c++
Article #3362Re: Legal C++ code?
From: Don Wallace
Date: Tue, 20 Feb 1996 15:44
Date: Tue, 20 Feb 1996 15:44
42 lines
1753 bytes
1753 bytes
tim@franck.Princeton.EDU (Tim Hollebeek) wrote:
>Is the following legal C++ code? g++ compiles it, but it doesn't link
>(undefined function Foo::foo()). I'm suprised it compiles at all:
>class Foo {
>public:
> virtual int foo() = 0;
>};
>class Bar : public Foo {
>public:
> int foo() { return Foo::foo(); }
>};
>int main() {
> Bar bar;
> bar.foo();
>}
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.
- Don
[ 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:
<4gbilr$38m@dub-news-svc-1.compuserve.com>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<4fvtk3$16j@cnn.Princeton.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: 71247.3221@compuserve.com (Don Wallace) Newsgroups: comp.std.c++ Subject: Re: Legal C++ code? Date: 20 Feb 1996 15:44:51 GMT Organization: CompuServe Incorporated Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <4gbilr$38m@dub-news-svc-1.compuserve.com> References: <4fvtk3$16j@cnn.Princeton.EDU> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: hd48-175.compuserve.com X-Newsreader: Forte Free Agent v0.55 Content-Length: 824 X-Lines: 35 Originator: clamage@taumet