Contents Up Previous Next

RTTI functions

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.

See also

RTTI overview

CLASSINFO
DECLARE_ABSTRACT_CLASS
DECLARE_APP
DECLARE_CLASS
DECLARE_DYNAMIC_CLASS
IMPLEMENT_ABSTRACT_CLASS
IMPLEMENT_ABSTRACT_CLASS2
IMPLEMENT_APP
IMPLEMENT_CLASS
IMPLEMENT_CLASS2
IMPLEMENT_DYNAMIC_CLASS
IMPLEMENT_DYNAMIC_CLASS2
wxConstCast
::wxCreateDynamicObject
WXDEBUG_NEW
wxDynamicCast
wxDynamicCastThis
wxStaticCast
wx_const_cast
wx_reinterpret_cast
wx_static_cast


CLASSINFO

wxClassInfo * CLASSINFO(className)

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

Include files

<wx/object.h>


DECLARE_ABSTRACT_CLASS

DECLARE_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. The same as DECLARE_CLASS.

Example:

class wxCommand: public wxObject
{
  DECLARE_ABSTRACT_CLASS(wxCommand)

 private:
  ...
 public:
  ...
};
Include files

<wx/object.h>


DECLARE_APP

DECLARE_APP(className)

This is used in headers to create a forward declaration of the wxGetApp function implemented by IMPLEMENT_APP. It creates the declaration className& wxGetApp(void).

Example:

  DECLARE_APP(MyApp)
Include files

<wx/app.h>


DECLARE_CLASS

DECLARE_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 DECLARE_ABSTRACT_CLASS.

Include files

<wx/object.h>


DECLARE_DYNAMIC_CLASS

DECLARE_DYNAMIC_CLASS(className)

Used inside a class declaration to declare that the objects of this class should be dynamically creatable from run-time type information.

Example:

class wxFrame: public wxWindow
{
  DECLARE_DYNAMIC_CLASS(wxFrame)

 private:
  const wxString& frameTitle;
 public:
  ...
};
Include files

<wx/object.h>


IMPLEMENT_ABSTRACT_CLASS

IMPLEMENT_ABSTRACT_CLASS(className, baseClassName)

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

Example:

IMPLEMENT_ABSTRACT_CLASS(wxCommand, wxObject)

wxCommand::wxCommand(void)
{
...
}
Include files

<wx/object.h>


IMPLEMENT_ABSTRACT_CLASS2

IMPLEMENT_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. The same as IMPLEMENT_CLASS2.

Include files

<wx/object.h>


IMPLEMENT_APP

IMPLEMENT_APP(className)

This is used in the application class implementation file to make the application class known to wxWidgets for dynamic construction. You use this instead of

Old form:

  MyApp myApp;
New form:

  IMPLEMENT_APP(MyApp)
See also DECLARE_APP.

Include files

<wx/app.h>


IMPLEMENT_CLASS

IMPLEMENT_CLASS(className, baseClassName)

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

Include files

<wx/object.h>


IMPLEMENT_CLASS2

IMPLEMENT_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. The same as IMPLEMENT_ABSTRACT_CLASS2.

Include files

<wx/object.h>


IMPLEMENT_DYNAMIC_CLASS

IMPLEMENT_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.

Example:

IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)

wxFrame::wxFrame(void)
{
...
}
Include files

<wx/object.h>


IMPLEMENT_DYNAMIC_CLASS2

IMPLEMENT_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 files

<wx/object.h>


wxConstCast

classname * 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.

See also

wx_const_cast
wxDynamicCast
wxStaticCast


::wxCreateDynamicObject

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.


WXDEBUG_NEW

WXDEBUG_NEW(arg)

This is defined in debug mode to be call the redefined new operator with filename and line number arguments. The definition is:

#define WXDEBUG_NEW new(__FILE__,__LINE__)
In non-debug mode, this is defined as the normal new operator.

Include files

<wx/object.h>


wxDynamicCast

classname * 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.

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

RTTI overview
wxDynamicCastThis
wxConstCast
wxStatiicCast


wxDynamicCastThis

classname * 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.

See also

wxDynamicCast


wxStaticCast

classname * 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).

See also

wx_static_cast
wxDynamicCast
wxConstCast


wx_const_cast

T 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.

See also

wx_reinterpret_cast,
wx_static_cast


wx_reinterpret_cast

T wx_reinterpret_cast(T, x)

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

See also

wx_const_cast,
wx_static_cast


wx_static_cast

T 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.

See also

wx_const_cast,
wx_reinterpret_cast