Last active
August 29, 2015 14:01
-
-
Save onqtam/a3f33e688314d7b52867 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <typeinfo> | |
struct A { | |
//virtual ~A(){} //#uncomment to enable rtti for this inheritance hierarchy | |
}; | |
struct B : A {}; | |
void func(A* a1, A* a2) { | |
if(typeid(*a1) == typeid(*a2)) | |
printf("they are the same!\n"); | |
//# do not compile unless there is polymorphism | |
//if(dynamic_cast<B*>(a1)) | |
// printf("wtf1\n"); | |
//if(dynamic_cast<B*>(a2)) | |
// printf("wtf2\n"); | |
printf("%s\n", typeid(*a1).name()); | |
printf("%s\n", typeid(*a2).name()); | |
} | |
int main(int argc, char** argv) { | |
A a; | |
B b; | |
func(&a,&b); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment