Debian Codegraph @

cmake/cxx_tests/rtti.cpp

raw
1 // DESCRIPTION
2 //
3 // Test to check whether the C++ compiler supports Run-Time Type
4 // Identification (typeinfo header and typeid keyword).
5 // In sync with AC_CXX_RTTI (2008-04-12).
6 //
7 // Copyright (c) 2009 Theo Papadopoulo <[email protected]>
8 //
9 // COPYLEFT
10 //
11 // Copyright (c) 2008 Todd Veldhuizen
12 // Copyright (c) 2008 Luc Maisonobe <[email protected]>
13 //
14 // Copying and distribution of this file, with or without modification, are
15 // permitted in any medium without royalty provided the copyright notice
16 // and this notice are preserved.
17
18 #include <typeinfo>
19
20 class Base {
21 public:
22 Base () {}
23 virtual int f () { return 0; }
24 };
25
26 class Derived: public Base {
27 public :
28 Derived () {}
29 virtual int f () { return 1; }
30 };
31
32 int main() {
33 Derived d;
34 Base *ptr = &d;
35 return typeid (*ptr) == typeid (Derived);
36 }