Mega Code Archive

 
Categories / C++ / Development
 

Demonstrate == and != relative to typeid

#include <iostream> #include <typeinfo> using namespace std; class X {   virtual void f() {} }; class Y {   virtual void f() {} }; int main() {   X x1, x2;   Y y1;   if(typeid(x1) == typeid(x2))     cout << "x1 and x2 are same types\n";   else     cout << "x1 and x2 are different types\n";   if(typeid(x1) != typeid(y1))     cout << "x1 and y1 are different types\n";   else     cout << "x1 and y1 are same types\n";   return 0; }