Getting the datatype of an object

In Java and C#, it’s really easy getting the datatype of an object that you are working with. If you don’t know what I am talking about, post a comment and I’ll explain it in more detail.Well anyway, surprisingly, I never had the need, until now, to do the same thing in C++. In other languages, you have the “typeof” keyword that allows you to get the datatype of an object.

This keyword exists on the Mac, but doesn’t do the same thing. To get the same type of functionality, you can use the “typeid” class to get the datatype and name of the object you are working on:

void GetMyType()

{

int i = 0;

cout << typeid(i).name();

}  

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *