equal
deleted
inserted
replaced
|
1 #include <typeinfo> |
|
2 #include <iostream> |
|
3 |
|
4 using namespace std; |
|
5 |
|
6 class A { |
|
7 public: |
|
8 void f () { |
|
9 cout << "Ich bin f() in der Klasse A\n"; |
|
10 } |
|
11 }; |
|
12 |
|
13 class B:public A { |
|
14 public: |
|
15 void f () { |
|
16 cout << "Ich bin f() in der Klasse B\n"; |
|
17 } |
|
18 }; |
|
19 |
|
20 class C { |
|
21 public: |
|
22 void f () { |
|
23 cout << "Ich bin auch ein f()\n"; |
|
24 } |
|
25 }; |
|
26 |
|
27 int main () |
|
28 { |
|
29 A *ap = new A (); |
|
30 B *bp = new B (); |
|
31 |
|
32 // instanceof |
|
33 C *cp = dynamic_cast < A * >(bp); |
|
34 if (cp != NULL) |
|
35 cp->f (); |
|
36 |
|
37 return 0; |
|
38 } |