| Version: 3.0.1

- Main Page
- Related Pages
- Categories
- Classes
- Files

Macros | Functions
Runtime Type Information (RTTI)
Functions and Macros by Category

## Detailed Description

wxWidgets uses its own RTTI ("run-time type identification") system which predates the current standard C++ RTTI and so is kept for backwards compatibility reasons but also because it allows some things which the standard RTTI doesn't directly support (such as creating a class from its name).

The standard C++ RTTI can be used in the user code without any problems and in general you shouldn't need to use the functions and the macros in this section unless you are thinking of modifying or adding any wxWidgets classes.

Related Overviews: Runtime Type Information (RTTI)

Related class group: Runtime Type Information (RTTI)

## Macros

#define | wxDECLARE_APP(className)
| This is used in headers to create a forward declaration of the wxGetApp() function implemented by wxIMPLEMENT_APP().
#define | wxIMPLEMENT_APP(className)
| This is used in the application class implementation file to make the application class known to wxWidgets for dynamic construction.
#define | wxCLASSINFO(className)
| Returns a pointer to the wxClassInfo object associated with this class.
#define | wxDECLARE_ABSTRACT_CLASS(className)
| Used inside a class declaration to declare that the class should be made known to the class hierarchy, but objects of this class cannot be created dynamically.
#define | wxDECLARE_DYNAMIC_CLASS(className)
| Used inside a class declaration to make the class known to wxWidgets RTTI system and also declare that the objects of this class should be dynamically creatable from run-time type information.
#define | wxDECLARE_CLASS(className)
| Used inside a class declaration to declare that the class should be made known to the class hierarchy, but objects of this class cannot be created dynamically.
#define | wxIMPLEMENT_ABSTRACT_CLASS(className, baseClassName)
| Used in a C++ implementation file to complete the declaration of a class that has run-time type information.
#define | wxIMPLEMENT_ABSTRACT_CLASS2(className, baseClassName1, baseClassName2)
| Used in a C++ implementation file to complete the declaration of a class that has run-time type information and two base classes.
#define | wxIMPLEMENT_DYNAMIC_CLASS(className, baseClassName)
| Used in a C++ implementation file to complete the declaration of a class that has run-time type information, and whose instances can be created dynamically.
#define | wxIMPLEMENT_DYNAMIC_CLASS2(className, baseClassName1, baseClassName2)
| Used in a C++ implementation file to complete the declaration of a class that has run-time type information, and whose instances can be created dynamically.
#define | wxIMPLEMENT_CLASS(className, baseClassName)
| Used in a C++ implementation file to complete the declaration of a class that has run-time type information, and whose instances can be created dynamically.
#define | wxIMPLEMENT_CLASS2(className, baseClassName1, baseClassName2)
| Used in a C++ implementation file to complete the declaration of a class that has run-time type information and two base classes, and whose instances can be created dynamically.
#define | wx_const_cast(T, x)
| Same as `const_cast<T>(x)` if the compiler supports const cast or ``(T)x for old compilers.
#define | wx_reinterpret_cast(T, x)
| Same as `reinterpret_cast<T>(x)` if the compiler supports reinterpret cast or ``(T)x for old compilers.
#define | wx_static_cast(T, x)
| Same as `static_cast<T>(x)` if the compiler supports static cast or ``(T)x for old compilers.
#define | wx_truncate_cast(T, x)
| This case doesn’t correspond to any standard cast but exists solely to make casts which possibly result in a truncation of an integer value more readable.
#define | wxConstCast(ptr, classname)
| This macro expands into `const_cast<classname *>(ptr)` if the compiler supports const_cast or into an old, C-style cast, otherwise.
#define | wxDynamicCast(ptr, classname)
| This macro returns the pointer ptr cast to the type classname * if the pointer is of this type (the check is done during the run-time) or NULL otherwise.
#define | wxDynamicCastThis(classname)
| This macro is equivalent to `wxDynamicCast(this, classname)` but the latter provokes spurious compilation warnings from some compilers (because it tests whether `this` pointer is non-NULL which is always true), so this macro should be used to avoid them.
#define | wxStaticCast(ptr, classname)
| This macro checks that the cast is valid in debug mode (an assert failure will result if wxDynamicCast(ptr, classname) == NULL) and then returns the result of executing an equivalent of `static_cast<classname *>(ptr)`.
#define | wxGetVariantCast(var, classname)
| This macro returns a pointer to the data stored in var (wxVariant) cast to the type classname if the data is of this type (the check is done during the run-time) or NULL otherwise.

## Functions

wxObject * | wxCreateDynamicObject (const wxString &className)
| Creates and returns an object of the given class, if the class has been registered with the dynamic class system using DECLARE...

## Macro Definition Documentation

#define wx_const_cast | ( |  | T,
|  |  | x
| ) |  |

Same as `const_cast<T>(x)` if the compiler supports const cast or ``(T)x for old compilers.

Unlike wxConstCast(), the cast it to the type `T` and not to `T *` and also the order of arguments is the same as for the standard cast.

Include file:

    #include <wx/defs.h>

See Also
  wx_reinterpret_cast(), wx_static_cast()

#define wx_reinterpret_cast | ( |  | T,
|  |  | x
| ) |  |

Same as `reinterpret_cast<T>(x)` if the compiler supports reinterpret cast or ``(T)x for old compilers.

Include file:

    #include <wx/defs.h>

See Also
  wx_const_cast(), wx_static_cast()

#define wx_static_cast | ( |  | T,
|  |  | x
| ) |  |

Same as `static_cast<T>(x)` if the compiler supports static cast or ``(T)x for old compilers.

Unlike wxStaticCast(), there are no checks being done and the meaning of the macro arguments is exactly the same as for the standard static cast, i.e. T is the full type name and star is not appended to it.

Include file:

    #include <wx/defs.h>

See Also
  wx_const_cast(), wx_reinterpret_cast(), wx_truncate_cast()

#define wx_truncate_cast | ( |  | T,
|  |  | x
| ) |  |

This case doesn’t correspond to any standard cast but exists solely to make casts which possibly result in a truncation of an integer value more readable.

Include file:

    #include <wx/defs.h>

#define wxCLASSINFO | ( |  | className | ) |

Returns a pointer to the wxClassInfo object associated with this class.

Include file:

    #include <wx/object.h>

#define wxConstCast | ( |  | ptr,
|  |  | classname
| ) |  |

This macro expands into `const_cast<classname *>(ptr)` if the compiler supports const_cast or into an old, C-style cast, otherwise.

Include file:

    #include <wx/defs.h>

See Also
  wx_const_cast(), wxDynamicCast(), wxStaticCast()

#define wxDECLARE_ABSTRACT_CLASS | ( |  | className | ) |

Used inside a class declaration to declare that the class should be made known to the class hierarchy, but objects of this class cannot be created dynamically.

Include file:

    #include <wx/object.h>

Example:

class wxCommand: public wxObject
{
wxDECLARE_ABSTRACT_CLASS(wxCommand);
private:
...
public:
...
};

#define wxDECLARE_APP | ( |  | className | ) |

This is used in headers to create a forward declaration of the wxGetApp() function implemented by wxIMPLEMENT_APP().

It creates the declaration `className& wxGetApp()` (requires a final semicolon).

Include file:

    #include <wx/app.h>

Example:

wxDECLARE_APP(MyApp);

#define wxDECLARE_CLASS | ( |  | className | ) |

Used inside a class declaration to declare that the class should be made known to the class hierarchy, but objects of this class cannot be created dynamically.

The same as wxDECLARE_ABSTRACT_CLASS().

Include file:

    #include <wx/object.h>

#define wxDECLARE_DYNAMIC_CLASS | ( |  | className | ) |

Used inside a class declaration to make the class known to wxWidgets RTTI system and also declare that the objects of this class should be dynamically creatable from run-time type information.

Notice that this implies that the class should have a default constructor, if this is not the case consider using wxDECLARE_ABSTRACT_CLASS().

Include file:

    #include <wx/object.h>

Example:

class wxFrame: public wxWindow
{
wxDECLARE_DYNAMIC_CLASS(wxFrame);
private:
const wxString& frameTitle;
public:
...
};

#define wxDynamicCast | ( |  | ptr,
|  |  | classname
| ) |  |

This macro returns the pointer ptr cast to the type classname * if the pointer is of this type (the check is done during the run-time) or NULL otherwise.

Usage of this macro is preferred over obsoleted wxObject::IsKindOf() function.

The ptr argument may be NULL, in which case NULL will be returned.

Include file:

    #include <wx/object.h>

Example:

wxWindow *win = wxWindow::FindFocus();
wxTextCtrl *text = wxDynamicCast(win, wxTextCtrl);
if ( text )
{
// a text control has the focus...
}
else
{
// no window has the focus or it is not a text control
}

See Also
  Runtime Type Information (RTTI), wxDynamicCastThis(), wxConstCast(), wxStaticCast()

#define wxDynamicCastThis | ( |  | classname | ) |

This macro is equivalent to `wxDynamicCast(this, classname)` but the latter provokes spurious compilation warnings from some compilers (because it tests whether `this` pointer is non-NULL which is always true), so this macro should be used to avoid them.

Include file:

    #include <wx/object.h>

See Also
  wxDynamicCast()

#define wxGetVariantCast | ( |  | var,
|  |  | classname
| ) |  |

This macro returns a pointer to the data stored in var (wxVariant) cast to the type classname if the data is of this type (the check is done during the run-time) or NULL otherwise.

Include file:

    #include <wx/variant.h>

See Also
  Runtime Type Information (RTTI), wxDynamicCast()

#define wxIMPLEMENT_ABSTRACT_CLASS | ( |  | className,
|  |  | baseClassName
| ) |  |

Used in a C++ implementation file to complete the declaration of a class that has run-time type information.

Include file:

    #include <wx/object.h>

Example:

wxIMPLEMENT_ABSTRACT_CLASS(wxCommand, wxObject);
wxCommand::wxCommand(void)
{
...
}

#define wxIMPLEMENT_ABSTRACT_CLASS2 | ( |  | className,
|  |  | baseClassName1,
|  |  | baseClassName2
| ) |  |

Used in a C++ implementation file to complete the declaration of a class that has run-time type information and two base classes.

Include file:

    #include <wx/object.h>

#define wxIMPLEMENT_APP | ( |  | className | ) |

This is used in the application class implementation file to make the application class known to wxWidgets for dynamic construction.

Note that this macro requires a final semicolon.

Include file:

    #include <wx/app.h>

Example:

wxIMPLEMENT_APP(MyApp);

See Also
  wxDECLARE_APP()

#define wxIMPLEMENT_CLASS | ( |  | className,
|  |  | baseClassName
| ) |  |

Used in a C++ implementation file to complete the declaration of a class that has run-time type information, and whose instances can be created dynamically.

The same as wxIMPLEMENT_DYNAMIC_CLASS().

Include file:

    #include <wx/object.h>

#define wxIMPLEMENT_CLASS2 | ( |  | className,
|  |  | baseClassName1,
|  |  | baseClassName2
| ) |  |

Used in a C++ implementation file to complete the declaration of a class that has run-time type information and two base classes, and whose instances can be created dynamically.

The same as wxIMPLEMENT_DYNAMIC_CLASS2().

Include file:

    #include <wx/object.h>

#define wxIMPLEMENT_DYNAMIC_CLASS | ( |  | className,
|  |  | baseClassName
| ) |  |

Used in a C++ implementation file to complete the declaration of a class that has run-time type information, and whose instances can be created dynamically.

Include file:

    #include <wx/object.h>

Example:

wxIMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow);
wxFrame::wxFrame(void)
{
...
}

#define wxIMPLEMENT_DYNAMIC_CLASS2 | ( |  | className,
|  |  | baseClassName1,
|  |  | baseClassName2
| ) |  |

Used in a C++ implementation file to complete the declaration of a class that has run-time type information, and whose instances can be created dynamically.

Use this for classes derived from two base classes.

Include file:

    #include <wx/object.h>

#define wxStaticCast | ( |  | ptr,
|  |  | classname
| ) |  |

This macro checks that the cast is valid in debug mode (an assert failure will result if wxDynamicCast(ptr, classname) == NULL) and then returns the result of executing an equivalent of `static_cast<classname *>(ptr)`.

Include file:

    #include <wx/object.h>

See Also
  wx_static_cast(), wxDynamicCast(), wxConstCast()

## Function Documentation

wxObject* wxCreateDynamicObject | ( | const wxString & | className | ) |

Creates and returns an object of the given class, if the class has been registered with the dynamic class system using DECLARE...

and IMPLEMENT... macros.

Include file:

    #include <wx/object.h>