[...]
This is not conformant. All virtual methods are "always"
virtual in your case. How do you manage virtual destructors
and virtual member functions called within constructors?
The compiler generates code in the constructors and destructors
to deregister from one registry, and re-register in another.
Just as it generates code today to change the vptr.
James, you are underestimating the complexity of the virtual
inheritance ;-)
assuming the following polymorphic types (with virtual member
functions) all holding a long integer of the same name (e.g. A has an
'a', B has an 'b', etc):
struct A { ... };
struct B { ... };
struct AB : virtual A, virtual B { ... };
struct BA : virtual B, virtual A { ... };
struct ABBA : AB, BA { ... };
here is what the ABBA ctor and its partial ctor_ must do (the dtor and
dtor_ do nearly the same in the reverse order):
// C++
ABBA(long a, long b, long ab, long ba, long abba_) :
A(a), B(b), AB(a,b,ab), BA(a,b,ba), abba(abba_) {}
// C equivalent
void ABBA_ctor(register ABBA* const this,
long a, long b, long ab, long ba, long abba)
{
A_ctor(BASE(this,A), a); /* compiler + user */
B_ctor(BASE(this,B), b); /* compiler + user */
AB_ctor_((AB*)this, ABBA_vtt, a, b, ab); /* compiler + user */
BA_ctor_(BASE(this,BA), ABBA_vtt+3, a, b, ba); /* compiler + user */
this->vptr = ABBA_vtbl; /* compiler */
this->BA_vptr = ABBA_BA_vtbl; /* compiler */
this->A_vptr = ABBA_A_vtbl; /* compiler */
this->B_vptr = ABBA_B_vtbl; /* compiler */
this->abba = abba; /* user */
}
// C equivalent, partial ctor, vtt is a table of vtbl
void ABBA_ctor_(register ABBA* const this, const VTABLE* const vtt[],
long a, long b, long ab, long ba, long abba)
{
AB_ctor_((AB*)this, vtt+4, a, b, ab);
BA_ctor_(BASE(this,BA), vtt+7, a, b, ba);
this->vptr = vtt[0];
this->BA_vptr = vtt[1];
VBASE(this,ABBA_A)->vptr = vtt[2];
VBASE(this,ABBA_B)->vptr = vtt[3];
this->abba = abba;
}
This code is part of my (unfinish) paper on the C++ object model from
2004. The code is completed, compiles and works and demonstrate how
all the machinery works. It can be found there
http://cern.ch/laurent.deniau/oopc.html#CPPObjModel
it is based on the paper of Nathan Sidwell, ACCU 2003. The cited
"Inside the C++ Object Model"
from Stanley B. Lippman is obsolete (does not reflect models currently
used) but still very didactic.
The reason this can't be made to work, as is, is because it
implies that the compiler know all of the derived classes at one
point. (Theoretically, I guess, the linker could generate these
functions, but practically, I don't think that's reasonable.)
Right. This is why I say that it cannot work.
If you drop separate compilation, it could.
Of course. All program analysis can do everything, but then you don't
need polymorphism at all ;-)
a+, ld.