"cbull" <cb***@poczta.onet.pl> schrieb im Newsbeitrag
news:dt**********@atlantis.news.tpi.pl...
class A
{
};
class B: public A
{
void f();
};
typedef void (A::*MPA)(void);
MPA mpA;
B b;
mpA = (MPA) &B::f;
b->*mpA();
Will it work? If not then when it will fail? I've heard something about
multi inheritance.
First I thought, such things cannot work, but after reading some pages of
the standard I have my doubts
4.11 (Standard Conversions) says "An rvalue of type "pointer to member of B
of type cv T," where B is a class type, can be converted to an rvalue of
type "pointer to member of D of type cv T," where D is a derived class
(clause 10) of B."
Later 5.2.9 (static_cast) says "An rvalue of type "pointer to member of D of
type cv1 T" can be converted to an rvalue of type "pointer to member of B of
type cv2 T", where B is a base class (clause 10) of D, if a valid standard
conversion from "pointer to member of B of type T" to "pointer to member of
D of type T" exists (4.11), and cv2 is the same cv-qualification as, or
greater cv-qualification than, cv1"
Putting those pieces together I come to the conclusion that it should work,
if I correctly understand those parts of the standards and didn't miss other
important parts (for this problem). According to 4.11 there is a standard
conversion from void(A::*)() [aka MPA] to void(B::*)(), and, according to
5.2.9, if there is such a conversion, you can explicitly cast from void
(B::*)() to void (A::*)() using a static_cast.
HTH
Heinz