#include <iostream>
#include <typeinfo>
struct A { virtual void Foo() {} };
struct B : public A { void Foo() {} };
struct C : public A { };
int main() {
std::cout << "naive - fails" << std::endl;
std::cout << int(&A::Foo == &A::Foo) << std::endl;
std::cout << int(&A::Foo == &B::Foo) << std::endl;
std::cout << int(&A::Foo == &C::Foo) << std::endl;
std::cout << "needs gcc-only PMF extension - semi-works" << std::endl;
std::cout << int(reinterpret_cast<void(*)()>(&A::Foo) == reinterpret_cast<void(*)()>(&A::Foo)) << std::endl;
std::cout << int(reinterpret_cast<void(*)()>(&A::Foo) == reinterpret_cast<void(*)()>(&B::Foo)) << std::endl;
std::cout << int(reinterpret_cast<void(*)()>(&A::Foo) == reinterpret_cast<void(*)()>(&C::Foo)) << std::endl;
std::cout << "proper solution - works" << std::endl;
std::cout << int(typeid(&A::Foo) == typeid(&A::Foo)) << std::endl;
std::cout << int(typeid(&A::Foo) == typeid(&B::Foo)) << std::endl;
std::cout << int(typeid(&A::Foo) == typeid(&C::Foo)) << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZWluZm8+CgpzdHJ1Y3QgQSB7IHZpcnR1YWwgdm9pZCBGb28oKSB7fSB9OwpzdHJ1Y3QgQiA6IHB1YmxpYyBBIHsgdm9pZCBGb28oKSB7fSB9OwpzdHJ1Y3QgQyA6IHB1YmxpYyBBIHsgfTsKCmludCBtYWluKCkgewoJc3RkOjpjb3V0IDw8ICJuYWl2ZSAtIGZhaWxzIiA8PCBzdGQ6OmVuZGw7CglzdGQ6OmNvdXQgPDwgaW50KCZBOjpGb28gPT0gJkE6OkZvbykgPDwgc3RkOjplbmRsOwoJc3RkOjpjb3V0IDw8IGludCgmQTo6Rm9vID09ICZCOjpGb28pIDw8IHN0ZDo6ZW5kbDsKCXN0ZDo6Y291dCA8PCBpbnQoJkE6OkZvbyA9PSAmQzo6Rm9vKSA8PCBzdGQ6OmVuZGw7CgoJc3RkOjpjb3V0IDw8ICJuZWVkcyB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