Last active
August 29, 2015 14:12
-
-
Save kris7t/d187d87f6fd60e92eced to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <iostream> | |
#include <typeinfo> | |
class B { | |
}; | |
class A { | |
public: | |
virtual ~A() = default; | |
}; | |
class C : public A { | |
public: | |
operator B() const { return B(); } | |
}; | |
int main() { | |
A *c = new C(); | |
try { | |
B b = dynamic_cast<const B &>(*c); | |
} catch (const std::bad_cast &) { | |
std::cout << "Why?!" << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment