dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Advanced
Dec 7, 1998

WEBINAR:

On-Demand


Capturing a type_info Object

The operator typeid returns a const type_info object associated with its argument. However, the returned object is a temporary one, so if you have to call several member functions from it, you will have to use the typeid expression repeatedly--a tedious and costly operation:
 
cout<<typeid(myObj).name() <<endl;
cout<<typeid(myObj).raw_name() <<endl; 
Note that you cannot copy-construct or assign the returned type_info object either:
 
type_info ti = typeid(myObj); //compilation error; copy constructor and operator= are private
 
As a workaround, you can initialize a reference or a pointer with the temporary object.
 
type_info *pti = & typeid (myObj) ;  // OK, a pointer with the address of the returned object
cout << pti->name()  << endl;
cout << pti->raw_name() << endl; 
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date