2 virtual-methods.hh -- declare macros for our do-it-yourself RTTI
4 source file of the Flower Library
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #ifndef VIRTUAL_METHODS_HH
11 #define VIRTUAL_METHODS_HH
15 #define classname(class_ptr) demangle_classname (typeid (* (class_ptr)))
18 demangle_classname (type_info const &);
22 Virtual copy constructor. Make up for C++'s lack of a standard
23 clone () function. Uses a typeof hack. Usage:
25 class Foo : Baseclass {
26 VIRTUAL_COPY_CONS (Baseclass);
31 // fix constness: gcc-2.95 is correct in defining
33 // in a const member function to be const
36 #define VIRTUAL_COPY_CONS(base) \
37 virtual base *clone () const \
39 return new typeof (*this) (*this); \
42 #define VIRTUAL_COPY_CONS(base) \
43 virtual base* clone_const_helper () \
45 return new typeof (*this) (*this); \
47 virtual base* clone () const \
49 base* urg = (base*)this; \
50 return urg->clone_const_helper (); \
54 #endif /* VIRTUAL_METHODS_HH */