typeid operator

   
typeid operator Runtime type identification operator

  postfix-expr  := typeid (  expression  )  typeid (  type-id  ) 

The typeid operator returns a const reference to a type_info object that describes type-id or the type of expression . If expression is an lvalue (not a pointer) of a polymorphic class, the type_info of the most-derived class is returned. Otherwise, expression is not evaluated, and the type_info of its static type is returned.

Each distinct type has its own associated type_info object, but type synonyms (such as those created with typedef ) have the same type_info object.

Example

 template<typename T> void debug(const T& obj) {   std::clog <<  typeid  (obj).name(  ) << ':' << &obj << '\n'; } 

See Also

expression , typedef , Chapter 3, <typeinfo>

   


C++ in a Nutshell
C++ in a Nutshell
ISBN: 059600298X
EAN: 2147483647
Year: 2005
Pages: 270
Authors: Ray Lischner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net