* Paolo Capriotti:
Compiling the following code (gcc 3.3.6), I get an invalid conversion
error.
Is there a valid reason why this conversion can't be performed?
class A {};
class B : public A {};
class T {
public:
B b;
};
int main() {
A T::*a = &T::b;
}
For the purposes of this group, the explanation is that §3.9.2/3 tells us that
statements regarding pointers do not apply to pointers to members (except for
pointers to static members), so that the general B* -> A* conversion doesn't
apply, and then §4.11 does not list the conversion above for member pointers.
As to why, I think that's a defect in the standard.
I cannot think of any reason why the standard should forbid this conversion,
but then I don't understand e.g. how the dynamic type of an object that a
pointer to member is applied to, can not contain that member, as mentioned in
§5.5/4 (except for perhaps pure virtual functions, but that's covered
elsewhere and I think if it was that then the standard would just say so).
--
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?