*
be******@gmail.com:
#include <iostream>
using namespace std;
class A {
};
class B {
};
class C : public A, public B {
};
int main() {
A *pA = 0;
B *pB = 0;
C c;
pA = &c;
pB = &c;
cout << sizeof(c) << endl;
cout << pA << " : " << pB << " : " << &c << endl;
return 0;
}
OUTPUT:
1
0012FF74 : 0012FF75 : 0012FF74
Why does sizeof return 1 but when looking at the pointers we get
addresses of two different bytes in memory?
At first sight I thought that must be wrong. But. Since classes A and
B are empty the compiler is free to apply the empty base class
optimization, reducing the size of each base class sub-object to zero.
It then has to represent a pointer to a base class object in some way,
and since there are two base classes, two different pointer values are
needed. All that's required is that if you cast back down you will
consistently get &c, and surely you do?
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?