I have an abstract interface I in which virtual void Foo() is defined, along with other functions. There are some subclasses in which Foo is re-defined, and others in which Foo is not. Now, given I* pi, is it possible to know whether Foo is re-defined? That is, I want to know whether pi->Foo() would call I::Foo() or X::Foo() where X is some type in which Foo is re-defined. I think this can be done by comparing function pointers, between &I::Foo and &pi->Foo, but not sure exactly how to. Note that I don’t know the concrete type of pi in runtime, so I cannot compare function pointers directly by &I::Foo != &X::Foo.
ADD:
So, a lot of people pointed that the design is bad, against the concept of abstraction and virtual functions. The main reason that I’m doing this is to bypass empty function calls to improve speed. Since some of Foo() are empty, I would like to remove it from a vector of pis, when Foo() is empty.
You can’t find out from
&pi->Foo, since, as the GCC error message will tell you,If you want to know the type of an object at runtime, use
typeid. Otherwise, rethink your design.