Re: Template technicality - What does the standard say?
On Wed, 15 Oct 2008 01:45:58 -0700 (PDT), James Kanze
<james.kanze@gmail.com> wrote:
On Oct 15, 3:06 am, Stephen Horne <sh006d3...@blueyonder.co.uk> wrote:
On Tue, 14 Oct 2008 15:58:15 -0700 (PDT), James Kanze
I'm sorry, but it's basic textbook. The compiler determines
what is inherited and places each inherited class at a
particualar offset within the derived class, as if it were
member data (which it is).
You must be reading the wrong textbooks (or you don't understand
virtual inheritance), since it's provably impossible to do so.
And it's simple to try:
struct VB
....
struct M : virtual VB
....
struct D : M
{
int d ;
} ;
....
M v1 ;
v1.f( std::cout ) ;
D v2 ;
v2.f( std::cout ) ;
return 0 ;
}
I get different values for the two variables with every compiler
I try.
What this proves is that you didn't read my post. You haven't
instantiated two instances of the same class - you have instantiated
two instances of *TWO* *DIFFERENT* *CLASSES*.
Given all your insistence on pedantic language, how can you not notice
that point?
The class M uses virtual inheritance, but it's not a dynamic entity in
itself. It's not a run-time entity at all. It has one layout. It isn't
the same layout that is used for D, even for those components that are
inherited from M, but that's what you get for using virtual
inheritance. As I pointed out elsewhere, even multiple inheritance
breaks offsetof if thats what you're dealing with.
This issue has NOTHING to do with applications which take the
following form...
template<typename T>
struct Node
{
T field_within_node;
};
....
x = offsetof (Node<M>, field_within_node);
Unless you're stupid enough to think the offset also applies to
instances of Node<D> which is a DIFFERENT TYPE, just as D is a
DIFFERENT TYPE to M.
Except that I can prove my statements. Both by example and by
formal proof.
But primarily by failing to read before you reply and obsessing on an
irrelevant issue, which invalidates both so-called proofs.
If you can't read what I post before replying (or is it that you can't
admit to a mistake?), I see no point in reading on.