How to determine whether a pointer of base (B
) class is (polymorphism-ly) override a certain virtual function of the base class?
class B{
public: int aField=0;
virtual void f(){};
};
class C : public B{
public: virtual void f(){aField=5;};
};
class D: public B{};
int main() {
B b;
C c;
D d;
std::vector<B*> bs;
bs.push_back(&b);
bs.push_back(&c);
bs.push_back(&d);
for(int n=0;n<3;n++){
//std::cout<<(bs[n]->f)==B::f<<std::endl;
//should print "true false true"
}
}
I tried to compare the address of function pointer bs[n]->f
against B::f
, but it is uncompilable.
I feel that this question might be duplicated, but I can't find (sorry).