Not so fast. Although the solution provided works well, always ask yourself why do you need to know the name of the class?
typeid() is a slow construct, it is evaluated at runtime. (Though the most compiler optimize it so as it can be determined at the compile time. This usually applies to object which do not emits polymorphism and complex inheritance)
Also note that type_info::name() will not yield same result on different implementations. My implementations prints 1A due to following code:
So, the bottom line is, that you shouldn't be needing type_info until your doing some dirty (albeit serious) work. Can we know why do you need to know the name of the object at the runtime?
Thanks for your answer guys...
I have a state machine implemented in c++. I have base class pointer that points to different stats class object at run time. At some point i need to know through this base pointer to which stat my base pointer is pointing to so that i can take some action.
my base pointer can point to either active,pending or inactive state class object.
if my base pointer is pointing to active class object then i need to avoid some action. So i was looking answer for this question. If there is something i can use from inbuilt c++ functionality otherwise i have to put some strings in base class saying what is the state of base pointer.
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...