🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Why allow virtual function calls in co

#2354
From: Steve Clamage
Date: Mon, 30 Oct 1995 17:53
38 lines
2068 bytes
In article 95Oct29144834@avs.cs.rpi.edu, vandevod@cs.rpi.edu (David Vandevoorde) writes:
>
>What was the argumentation that lead to give defined semantics to
>calls to virtual functions in constructors?

The C++ object model is simple and consistent: When a constructor for
type T is invoked, it creates a T object out of raw storage. It doesn't
matter who invoked it or why. With single inheritance, which was all
that C++ supported when the object model was developed, there is no
reason to disallow calls to virtual functions under this model.

The one problem occurs for virtual base classes under multiple inheritance.
The offsets in the vtables for intermediate base classes are wrong during 
construction. If multiple inheritance had been in C++ from the beginning,
I suspect a different object model would have been developed.

>SC> I think you would have to add this feature, or else disallow
>SC> virtual calls from constructors and destructors.
>
>Right now, I think it makes sense disallowing them.

The problem is actually a little more subtle. You also have to disallow
passing the value of "this" out of a constructor or destructor, or 
make the results of doing so undefined. A constructor (destructor) for T
might call an ordinary global function which takes a pointer to T and
calls a virtual function.

---
Steve Clamage, stephen.clamage@eng.sun.com




---
[ 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: <472ujv$ns0@engnews1.eng.sun.com>
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt
References: <VANDEVOD.95Oct29144834@avs.cs.rpi.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Why allow virtual function calls in co
Date: 30 Oct 1995 17:53:08 GMT
Organization: Sun Microsystems Inc.
Approved: Matt@Austern
Message-ID: <472ujv$ns0@engnews1.eng.sun.com>
References: <VANDEVOD.95Oct29144834@avs.cs.rpi.edu>
Reply-To: clamage@Eng.Sun.COM
NNTP-Posting-Host: austern.hip.berkeley.edu