On Sep 2, 3:28 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
"Curiosity" is not really a valid reason, I believe. So, really, why
would you want to do that? You're not using the pointer-to-member in
any way, so what would be the point of returning it?
Well, it is for me... :-)
To answer your question: Suppose you have an arbitrarily large
inheritance hierarchy with root class A, and you want to know if some
subclass reimplements f. If you know the class, no problem. Just test
&A::f == &B::f
or whatever other class, and it's done. Now, suppose you don't know
the class because all you have is a polymorphic pointer to an object
(like in "A* obj"). In this case you would test
&A::f == getFAddress(obj)
With my example code, this would be true if the class of *obj is A,
and false if it's B. Moreover, you don't know all the classes from the
inheritance hierarchy, so you can't (or don't want to) check your
object against all the classes using typeid, or dynamic_cast, or
whatever.
As for the final purpose of this, I don't have any. If you want to
know, it's just an idea I had when trying to deal with exceptions in
event handlers using the wxWidgets framework. But I've found a better
solution, at least more -- let's say -- natural.
You can use metaprogramming technique to query if a class implements f.