2 virtual-methods.hh -- declare macros for our do-it-yourself RTTI
4 source file of the Flower Library
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #ifndef VIRTUAL_METHODS_HH
10 #define VIRTUAL_METHODS_HH
14 #define classname(class_ptr) demangle_classname (typeid (* (class_ptr)))
17 demangle_classname (std::type_info const &);
19 /* Virtual copy constructor. Make up for C++'s lack of a standard
20 factory or clone () function. Uses a typeof hack. Usage:
24 VIRTUAL_COPY_CONSTRUCTOR (Baseclass, Foo);
27 #define VIRTUAL_COPY_CONSTRUCTOR(base, name) \
28 /* Hack to fix constness: gcc >= 2.95 is correct in defining \
29 typeof (*this) in a const member function to be const. */ \
30 virtual base* clone_const_helper () \
32 return new name (*this); \
34 virtual base *clone () const \
36 /* return new name (*this); */ \
37 base *urg = (base*) this; \
38 return urg->clone_const_helper (); \
41 #endif /* VIRTUAL_METHODS_HH */