Article View: comp.std.c++
Article #2396Re: Virtual calls on unfinished objects (was:
From: kanze
Date: Thu, 02 Nov 1995 16:06
Date: Thu, 02 Nov 1995 16:06
58 lines
2594 bytes
2594 bytes
In article <4760hc$llf@cnn.Princeton.EDU> tim@franck.Princeton.EDU
(Tim Hollebeek) writes:
|> In article <475jnr$1sv@engnews1.eng.sun.com>,
|> Steve Clamage <clamage@Eng.Sun.COM> wrote:
|> >Let's restore some context. We were talking about changing the C++ object
|> >model. Under the current model, calls to virtual functions are well-
|> >defined from constructors and destructors: you get the same result as
|> >if the constructor's (destructor's) type were the complete object.
|> They are well-defined, but defined in such a way that is at best
|> confusing and error-prone (despite being consistent and predictable).
|> I recently got bit by this one in the form:
|> ---
|> class A {
|> public:
|> virtual void close() {
|> cerr << "A::close()\n";
|> }
|> virtual ~A() {
|> cerr << "~A()\n";
|> close();
|> }
|> };
|> class B : public A {
|> void close() {
|> cerr << "B::close()\n";
|> }
|> };
|> ---
|> The call to close() LOOKS like a normal call to a virtual function,
|> unless you remember that there is an 'exception' in the language for
|> this case.
The call to close() not only looks like a normal call to a virtual
function, it *is* a normal call to a virtual function. On an object
whose dynamic type is A.
This would seem like the normal behavior to me.
Just out of curiousity, how do other languages which have constructors
and dynamic typing handle this?
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<9511021159.AA01876@slsv7xt.lts.sel.alcatel.de>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<VANDEVOD.95Oct30130647@avs.cs.rpi.edu> <475jnr$1sv@engnews1.eng.sun.com> <4760hc$llf@cnn.Princeton.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: kanze <kanze@lts.sel.alcatel.de> Newsgroups: comp.std.c++ Subject: Re: Virtual calls on unfinished objects (was: Date: 2 Nov 1995 16:06:16 GMT Organization: ? Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <9511021159.AA01876@slsv7xt.lts.sel.alcatel.de> References: <VANDEVOD.95Oct30130647@avs.cs.rpi.edu> <475jnr$1sv@engnews1.eng.sun.com> <4760hc$llf@cnn.Princeton.EDU> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text In-Reply-To: tim@franck.Princeton.EDU's message of 31 Oct 1995 23:07:20 GMT Content-Length: 1692 Originator: clamage@taumet