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 <stdio.h>
27#include <typeinfo>
28
29class A
30{
31public:
32 A()
33 {
34 printf("A: constructor called\n");
35 }
36
37 virtual ~A()
38 {
39 }
40
41 A *
42 clone()
43 {
44 typeof(this) a = new typeof(*this);
45 return a;
46 }
47};
48
49class B : public A
50{
51public:
52 B()
53 {
54 printf("B: constructor called\n");
55 }
56};
57
58int
59main(int argc, char **argv)
60{
61 B b;
62 A *a = b.clone();
63
64 printf("Type of a: %s\n", typeid(a).name());
65
66 B *ba;
67 if ((ba = dynamic_cast<B *>(a)) != NULL) {
68 printf("Dynamic cast of a as B successful\n");
69 } else {
70 printf("Dynamic cast of a as B FAILED\n");
71 }
72
73 delete a;
74}
75
76/// @endcond