Jeff Schwab wrote in news:8Z********************@comcast.com:
Each of d's subobjects, the a, the b, and m, must have a unique
address.
So, an instance of d must span at least enough address space to make
this possible, and to guarantee proper alignment of m. If this makes
you unhappy, Google for the Empty Base Optimization.
This is a matter of debate, Each subobject of the same type *must* have
a unique address.
i.e:
struct empty {};
struct derived : empty
{
empty value;
};
EBO can't work above as that would leave derived::value having the
same address as derived::empty.
VC7.1, and Borland 5.x (with EBO turned on) agrees with you.
g++ 3.2.3 and 3.4 (prerelese) and CBuilder X (preview) (EDG) agrees
with the above.
My test programme:
#include <iostream>
#include <ostream>
struct a
{
};
struct b
{
};
struct d : public a, public b
{
int m;
};
struct empty {};
struct derived : empty
{
empty value;
};
int main()
{
using namespace std;
d dd;
cerr << &dd.m << '\n';
cerr << static_cast< a *>( &dd ) << '\n';
cerr << static_cast< b *>( &dd ) << '\n';
cerr << sizeof(d) << '\n';
derived der;
cerr << &der.value << '\n';
cerr << static_cast< empty *>( &der ) << '\n';
cerr << sizeof(derived) << '\n';
}
Interetingly VC7.1 and Borland 5.x give derived::value the same address
as derived::empty (VC7.1 also gives sizeof( derived ) as 1). All the
others got it write.
Rob.
--
http://www.victim-prime.dsl.pipex.com/