Ben Hutchings
David Abrahams wrote:
Ben Hutchings
writes: Actually it can:
struct D : C { void foo(std::string); };
mem_fun mf = static_cast
(&D::foo); Not that I'd recommend doing that, as it invites type errors. Creating an instance by breaking the type system is cheating.
That doesn't break the type system. The result is well-defined; see 5.2.9/9 in the standard.
If class B contains the original member, or is a base or derived class of the class containing the original member, the resulting pointer to member points to the original member. Otherwise, the result of the cast is undefined. [Note: although class B need not contain the original member, the dynamic type of the object on which the pointer to member is dereferenced must contain the original member; see expr.mptr.oper. ] That part in brackets contradicts you in this case. But then, it's non-normativve and the section it references seems to actually only apply when the pointer is dereferenced. I'm slightly confused.
Why not reinterpret_cast
("foo"), for that matter? That's ill-formed.
Where is that in the standard? I see no restrictions on the use of reinterpret_cast.
A simpler instance of the type is: mem_fun mf = 0;
Yes, and as you know that's what the type trait relies on.
No, I didn't. -- Dave Abrahams Boost Consulting www.boost-consulting.com