Fawkes API Fawkes Development Version

qa_socket_typeof.cpp

00001 
00002 /***************************************************************************
00003  *  qa_socket_typeof.cpp - Fawkes QA for typeof, used in Socket::accept()
00004  *
00005  *  Created: Fri Nov 10 10:33:08 2006 (on train to Google, Hamburg)
00006  *  Copyright  2006  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 /// @cond QA
00025 
00026 #include <typeinfo>
00027 
00028 #include <stdio.h>
00029 
00030 class A
00031 {
00032  public:
00033   A()
00034   {
00035     printf("A: constructor called\n");
00036   }
00037 
00038   virtual ~A() {}
00039 
00040   A *
00041   clone()
00042   {
00043     typeof(this) a = new typeof(*this);
00044     return a;
00045   }
00046 };
00047 
00048 
00049 class B : public A
00050 {
00051  public:
00052   B()
00053   {
00054     printf("B: constructor called\n");
00055   }
00056 
00057 };
00058 
00059 
00060 int
00061 main(int argc, char **argv)
00062 {
00063   B b;
00064   A *a = b.clone();
00065 
00066   printf("Type of a: %s\n", typeid(a).name());
00067 
00068   B *ba;
00069   if ( (ba = dynamic_cast<B *>(a)) != NULL ) {
00070     printf("Dynamic cast of a as B successful\n");
00071   } else {
00072     printf("Dynamic cast of a as B FAILED\n");
00073   }
00074 
00075   delete a;
00076 }
00077 
00078 /// @endcond
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends