Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
GLOBAL_BAD_CAST.cpp
Go to the documentation of this file.
1// checking for class ::bad_cast
2
3
25#include "config.h"
26
27
28#ifndef _RWSTD_NO_HONOR_STD
29# ifdef _RWSTD_NO_STD_TERMINATE
30# include "terminate.h"
31# endif // _RWSTD_NO_STD_TERMINATE
32#endif // _RWSTD_NO_HONOR_STD
33
34
35class bad_cast { };
36
37
38struct B { virtual ~B () { } };
39struct D1: B { };
40struct D2: B { };
41
42int main ()
43{
44 D1 d1;
45 B &b = d1;
46
47 try {
48 // throws [std::]bad_cast
49 D2 &d2 = dynamic_cast<D2&>(b);
50 (void)&d2;
51 }
52 catch (bad_cast&) {
53 return 0;
54 }
55 catch (...) {
56 // fail if cast throws anything other than a ::bad_cast
57 return 1;
58 }
59
60 // fail if cast doesn't throw
61 return 2;
62}
#define d1
Definition 17.names.cpp:228
#define b
Definition 17.names.cpp:110
#define d2
Definition 17.names.cpp:254
int main()
virtual ~B()