Tuesday, January 10, 2012

typeid(expression)

typeid(expression) return an type_info object of expression. To read get the name of the type_info, call it's name() method.

Example:
typeid(expression)
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 cout << "typeid(): " << endl << endl;

 cout << "typeid(0.1234): " << typeid(0.1234).name() << endl;
 cout << "typeid(45): " << typeid(45).name() << endl;
 cout << "typeid(0.1234 * 45): " << typeid(0.1234 * 45).name() << endl;

 short shortArray[4];


 cout << "typeid(shortArray): " << typeid(shortArray).name() << endl;
 cout << "typeid(\"Hello\"): " << typeid("Hello").name() << endl;
 cout << "typeid(true): " << typeid(true).name() << endl;

 system("PAUSE");
 return 0;
}




No comments:

Post a Comment