Skip to content

Instantly share code, notes, and snippets.

@kris7t
Last active August 29, 2015 14:12
Show Gist options
  • Save kris7t/d187d87f6fd60e92eced to your computer and use it in GitHub Desktop.
Save kris7t/d187d87f6fd60e92eced to your computer and use it in GitHub Desktop.
#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