G
Gianni Mariani
While digging for a work around for a VC++7.1 compiler bug I came to
find an interesting thing about pointer to member conversions.
struct A
{
int a;
};
struct B : A
{
int b;
};
typedef int A::* A_mptr;
typedef int B::* B_mptr;
B_mptr bptr1 = &B::a; // ok no probs
A_mptr aptr1 = &B::a; // hmm converts B::a to A::a ***
A_mptr aptr2 = &B::b; // error - spooky - knows it can't do this
int main()
{
bptr1 = aptr1; // works - a way to get to private members eh?
aptr1 = bptr1; // error - as expected
}
I would have expected that line *** would have created an error but I
can see that in this case the compiler's behaviour is more interesting.
So there is somthing magic about (&B::a) that am object of type B_mptr
just does not have ?
find an interesting thing about pointer to member conversions.
struct A
{
int a;
};
struct B : A
{
int b;
};
typedef int A::* A_mptr;
typedef int B::* B_mptr;
B_mptr bptr1 = &B::a; // ok no probs
A_mptr aptr1 = &B::a; // hmm converts B::a to A::a ***
A_mptr aptr2 = &B::b; // error - spooky - knows it can't do this
int main()
{
bptr1 = aptr1; // works - a way to get to private members eh?
aptr1 = bptr1; // error - as expected
}
I would have expected that line *** would have created an error but I
can see that in this case the compiler's behaviour is more interesting.
So there is somthing magic about (&B::a) that am object of type B_mptr
just does not have ?