Fawkes API  Fawkes Development Version
qa_socket_typeof.cpp
1 
2 /***************************************************************************
3  * qa_socket_typeof.cpp - Fawkes QA for typeof, used in Socket::accept()
4  *
5  * Created: Fri Nov 10 10:33:08 2006 (on train to Google, Hamburg)
6  * Copyright 2006 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 /// @cond QA
25 
26 #include <typeinfo>
27 
28 #include <stdio.h>
29 
30 class A
31 {
32  public:
33  A()
34  {
35  printf("A: constructor called\n");
36  }
37 
38  virtual ~A() {}
39 
40  A *
41  clone()
42  {
43  typeof(this) a = new typeof(*this);
44  return a;
45  }
46 };
47 
48 
49 class B : public A
50 {
51  public:
52  B()
53  {
54  printf("B: constructor called\n");
55  }
56 
57 };
58 
59 
60 int
61 main(int argc, char **argv)
62 {
63  B b;
64  A *a = b.clone();
65 
66  printf("Type of a: %s\n", typeid(a).name());
67 
68  B *ba;
69  if ( (ba = dynamic_cast<B *>(a)) != NULL ) {
70  printf("Dynamic cast of a as B successful\n");
71  } else {
72  printf("Dynamic cast of a as B FAILED\n");
73  }
74 
75  delete a;
76 }
77 
78 /// @endcond