Hence I have a class, and want to determine whether it has a virtual function or not.
The first way to do I considered by dynamic cast.
class A
{
// hidden details..
};
class B:public A{};
int main()
{
A *a = new A;;
B* b = dynamic_cast<B*>(a);
}
So in this case if there is a virtual function in class A, the compile will succeed, otherwise, this error will occur:
error: cannot dynamic_cast \u2018a\u2019 (of type \u2018class A*\u2019) to type \u2018class B*\u2019 (source type is not polymorphic)
Is there a way to check this without compile error? NOTE: I have no c++11 or boost support!
std::is_polymorphic
. – Profound