Runtime Type Information

   

fr:Run-time type information

This article should be merged with datatype or runtime.

Runtime Type Information is information about an object's datatype that is set into memory at runtime.

Run Time Type Information is a computer programming term used to identify that a given language has the ability to determine the type of a program's object/variable at runtime.

Although available in most computer languages, RTTI, as a term, is typically used in relation to C++. In order for the dynamic_cast<> operation to work in C++, RTTI must be enabled.

An instance where RTTI is used is illustrated below:


class base {
};

class derived : public base {
   int compare(derived &ref);
};

int my_comparison_method_for_generic_sort(base &ref1, base &ref2)
{
    derived d = dynamic_cast<derived &>(ref1);  // rtti used here
    // rtti enables the process to throw a bad_cast exception
    // if the cast is not successfull
    return d.compare(dynamic_cast<derived &>(ref2));
}

Retrieved from "http://www.mywiseowl.com/articles/Runtime_Type_Information"

This page has been accessed 63 times. This page was last modified 15:37, 31 Oct 2004. All text is available under the terms of the GNU Free Documentation License (see Copyrights for details).