cpprttidisabled.h 3.2 KB

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