Skip to content

Commit 92d94ea

Browse files
authored
Update 007_any_bad_any_cast.cpp
1 parent da25020 commit 92d94ea

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

cpp_17/007_any_bad_any_cast.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
1
1+
#include <iostream>
2+
#include <typeinfo>
3+
4+
struct Foo { virtual ~Foo() {} };
5+
struct Bar { virtual ~Bar() {} };
6+
7+
int main()
8+
{
9+
Bar b;
10+
try {
11+
Foo& f = dynamic_cast<Foo&>(b);
12+
} catch(const std::bad_cast& e)
13+
{
14+
std::cout << e.what() << '\n';
15+
}
16+
}

0 commit comments

Comments
 (0)