Article View: comp.std.c++
Article #1783Re: virtual base class construction
From: John Max Skaller
Date: Tue, 15 Aug 1995 02:58
Date: Tue, 15 Aug 1995 02:58
62 lines
2659 bytes
2659 bytes
In article <40g1nl$2jo@gabi.gabi-soft.fr>, J. Kanze <kanze@gabi-soft.fr> wrote:
>John Max Skaller (maxtal@Physics.usyd.edu.au) wrote:
>
>|> For example how do you do assignments in the presence of
>|> virtual bases? What stops the data of the virtual base being assigned
>|> more than once?
>
> C&
> C::operator( C const& other )
> {
> if ( this != &other )
> {
> this->~C() ;
> new ( this ) C( other ) ;
> }
> return *this ;
> }
>
>No duplicate assignment of the virtual bases of C.
I don't understand, this does NOT work. This stops
an object being assigned to itself. That isn't the problem.
The problem is:
B
/ L R
/
D
If the assignment of D calls the assignments of L and R
before assigning the non-inherited members of D, and
the assignments of L and R each call the assignment of B
before assigning their non-inherited members, then the
assignment of B is called TWICE.
In the case of assigments entirely generated by the compiler,
it is possible for the compiler to do the right thing.
AFAIK the committee has NOT required this: double assignment
is permitted. (I hate this but I can live with it)
In the case where USER written assignments are involved
AS WELL as compiler generated assignments, there is NO way
to ensure the compiler does the right thing.
If you define all the assignments yourself you can arrange to
prevent duplicate assignments of members.
The problem ONLY arises for virtual bases, and it is not
important if they contain no data. Note assigments do NOT
copy virtual table pointers, so assignments of classes without
data can be optimised away. This is why I can probably live
with the current rule.
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd,
81A Glebe Point Rd, GLEBE Mem: SA IT/9/22,SC22/WG21
NSW 2037, AUSTRALIA Phone: 61-2-566-2189
---
[ 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:
<40nvlf$al@metro.ucc.su.OZ.AU>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<648258751wnr@hi-q.demon.co.uk> <3up5ne$4gv@fsgm01.fnal.gov> <401gnk$mk0@metro.ucc.su.OZ.AU> <40g1nl$2jo@gabi.gabi-soft.fr>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 15 Aug 95 02:58:14 GMT Approved: fjh@cs.mu.oz.au Return-Path: <daemon@ncar.UCAR.EDU> From: maxtal@Physics.usyd.edu.au (John Max Skaller) Newsgroups: comp.std.c++ Subject: Re: virtual base class construction X-Original-Date: 14 Aug 1995 17:03:43 GMT Organization: School of Physics, University of Sydney, Australia Message-ID: <40nvlf$al@metro.ucc.su.OZ.AU> References: <648258751wnr@hi-q.demon.co.uk> <3up5ne$4gv@fsgm01.fnal.gov> <401gnk$mk0@metro.ucc.su.OZ.AU> <40g1nl$2jo@gabi.gabi-soft.fr>