Hi,
I've got the following code which demonstrates a problem and am hoping someone can explain:
Code:
struct A
{
double x[2];
double i;
};
struct B : virtual public A
{
double y[2];
};
int main(void)
{
B test;
test.x[0] = 300;
test.i = -5;
A const * const pA = &test;
B const * const pB = &test;
bool const b = reinterpret_cast<int const *>(pA)
!= reinterpret_cast<int const *>(pB); // As expected
double (B::*pmemberBBi) = &B::i;
double (B::*pmemberBBx)[2] = &B::x;
double (A::*pmemberABx)[2] = &B::x;
double const * const pBBi_B = &(pB->*pmemberBBi); // Valid pointer even though pointer to derived
double const * const pBB_B = pB->*pmemberBBx ; // Null pointer, but why if the previous line worked?
double const * const pAB_B = pB->*pmemberABx ; // Works (pointer to base)
double bbi_b = pB->*pmemberBBi ; // Works fine even though it is pointer to derived
double bb_b = (pB->*pmemberBBx)[0]; // Crash, but why if the previous line worked?
double ab_b = (pB->*pmemberABx)[0]; // Works (pointer to base)
return 0;
}
I'm wondering if this is a compiler bug. Why doesn't the pointer-to-(derived)-member work for the array if it works for the non-array?
Thanks,
GeoRanger