]>
git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/overviews/cpprttidisabled.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cpprttidisabled.h
3 // Purpose: topic overview
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
11 @page overview_cpp_rtti_disabled Caveats When Not Using C++ RTTI
15 @see @ref overview_rtti, wxEvtHandler::Bind(), wxAny
19 @section overview_cpp_rtti_disabled_intro Introduction
21 @note C++ RTTI is usually enabled by default in most wxWidgets builds. If you
22 do not know if your build has C++ RTTI enabled or not, then it probably
23 is enabled, and you should not worry about anything mentioned in this
26 While in general wxWidgets standard @ref overview_rtti is used throughout the
27 library, there are some places where it won't work. One of those places
30 When available, C++ RTTI is used to address this issue. If you have built the
31 library with C++ RTTI disabled, an internal RTTI system is substituted.
32 However, this system is not perfect and one proven scenario where it may break
33 is a shared library or DLL build. More specifically, a template class instance
34 created in one physical binary may not be recognized as its correct type when
39 @section overview_cpp_rtti_disabled_bind Bind() Issues
41 wxWidgets 2.9.0 introduced a new @ref overview_events_bind system, using
42 wxEvtHandler::Bind<>() and Unbind<>(). This functionality uses templates
43 behind the scenes and therefore is vulnerable to breakage in shared library
44 builds, as described above.
46 Currently only Unbind<>() needs the type information, so you should be immune
47 to this problem simply if you only need to use Bind<>() and not Unbind<>().
49 Also, if you only bind and unbind same event handler inside same binary, you
54 @section overview_cpp_rtti_disabled_wxany wxAny Issues
56 wxAny is a dynamic type class which transparently uses templates to generate
57 data type handlers, and therefore is vulnerable to breakage in shared library
58 builds, as described above
60 You should be fine if you only create and use wxAny instances inside same
61 physical binary. However, if you do need to be able to use wxAny freely
62 across binary boundaries, (and for sake of code-safety, you probably do),
63 then specializations for wxAnyValueTypeImpl<> templates need to be defined in
64 one of your shared library (DLL) files. One specialization is required for
65 every data type you use with wxAny. Easiest way to do this is using macros
66 provided in wx/any.h. Note that you @b do @b not need to define
67 specializations for C built-in types, nor for wxString or wxDateTime, because
68 these are already provided in wxBase. However, you @b do need to define
69 specializations for all pointer types except char* and wchar_t*.
71 Let's define a specialization for imaginary type 'MyClass'. In your shared
72 library source code you will need to have this line:
75 WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<MyClass>)
78 In your header file you will need the following:
81 wxDECLARE_ANY_TYPE(MyClass, WXIMPORT_OR_WXEXPORT)
84 Where WXIMPORT_OR_WXEXPORT is WXEXPORT when being included from the shared
85 library that called the WX_IMPLEMENT_ANY_VALUE_TYPE() macro, and WXIMPORT