Re: multiple inheritance: H2 forbid some destructor?
On Mar 19, 12:25 pm, Bart van Ingen Schenau
<Bart.van.Ingen.Sche...@ict.nl> wrote:
On Mar 18, 6:40 pm, nguillot <nicolas.guil...@gmail.com> wrote:
<snip>
[...]
I would expect something like removing the A() {}, but is is
needed to instantiate B and C.
No, it is not.
The problem is that, due to an oversight, the standard
requires that even in abstract classes the constructor
contains an invocation of the constructor of the virtual base
classes, which will never be used anyway.
It's not really an oversight, but the rationale is based on
implementation considerations.
There are basically two ways to make A::A() unavailable to the
developers:
1. You remove it completely, and change the constructors of B and C to
call the constructor of A with a dummy value:
B::B() : A(0) {}
Because A is a virtual base-class, only the constructor mentioned in
the most-derived class will be used. All the constructor-calls to A
from intermediate base-classes will be ignored.
2. You make the constructor A::A() private, and declare B and C as
friends of A.
3. You provide a constructor A::A() which aborts with an error
message.
In these sort of cases, I usually use 3.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34