Run-time type information

Run-time type information

In programming, RTTI (Run-Time Type Information, or Run-Time Type Identification) refers to a C++ system that keeps information about an object's data type in memory at runtime. Run-time type information can apply to simple data types, such as integers and characters, or to generic objects. It's the C++ implementation of a more generic concept called reflection.

In order for the dynamic_cast<> operation, the typeid operator or exceptions to work in C++, RTTI must be enabled.

C++ Example

/* A base class pointer can point to objects of any class which is derived * from it. RTTI is useful to identify which type (derived class) of object is * pointed by a base class pointer. */

#include

class abc // base class{public: virtual void hello() { std::cout << "in abc"; ;

class xyz : public abc{ public: void hello() { std::cout << "in xyz"; ;

int main(){ abc *abc_pointer = new xyz(); xyz *xyz_pointer;

// to find whether abc is pointing to xyz type of object xyz_pointer = dynamic_cast(abc_pointer);

if (xyz_pointer != NULL) std::cout << "abc pointer is pointing to a xyz class object"; // identified else std::cout << "abc pointer is NOT pointing to a xyz class object";

delete abc_pointer;

return 0;}

----

An instance where RTTI is used is illustrated below:

class base { virtual ~base(){;

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

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

See also

* Reflection


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Run-time type information — En informatique, Run Time Type Information est utilisé pour signaler la capacité d un langage de programmation à déterminer le type d une variable pendant l exécution d un programme. Bien que disponible dans la plupart des langages de… …   Wikipédia en Français

  • Run-time algorithm specialisation — In computer science, run time algorithm specialisation is a methodology for creating efficient algorithms for costly computation tasks of certain kinds. The methodology originates in the field of automated theorem proving and, more specifically,… …   Wikipedia

  • Type system — Type systems Type safety Inferred vs. Manifest Dynamic vs. Static Strong vs. Weak Nominal vs. Structural Dependent typing Duck typing Latent typing Linear typing Uniqueness typing …   Wikipedia

  • Type safety — In computer science, type safety is a property of some programming languages that is defined differently by different communities, but most definitions involve the use of a type system to prevent certain erroneous or undesirable program behavior… …   Wikipedia

  • Information security — Components: or qualities, i.e., Confidentiality, Integrity and Availability (CIA). Information Systems are decomposed in three main portions, hardware, software and communications with the purpose to identify and apply information security… …   Wikipedia

  • Information technology audit process — Information technology audit process:Generally Accepted Auditing Standards (GAAS)In 1947, the American Institute of Certified Public Accountants (AICPA) adopted GAAS to establish standards for audits. The standards cover the following three… …   Wikipedia

  • Time for Annihilation — Time for Annihilation...On the Record and On the Road Studio album / Live album by Papa Roach …   Wikipedia

  • Time travel — This article details time travel itself. For other uses, see Time Traveler. Time travel is the concept of moving between different moments in time in a manner analogous to moving between different points in space, either sending objects (or in… …   Wikipedia

  • information system — Introduction       an integrated set of components for collecting, storing, processing, and communicating information (information science). Business firms, other organizations, and individuals in contemporary society rely on information systems… …   Universalium

  • run */*/*/ — I UK [rʌn] / US verb Word forms run : present tense I/you/we/they run he/she/it runs present participle running past tense ran UK [ræn] / US past participle run 1) [intransitive] to move quickly to a place using your legs and feet You ll have to… …   English dictionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”