How to use typeid to get the type name as defined by use typedef

Here's my problem:

I defined a new type and used a new type to declare a variable:

typedef int new_type;
new_type value;

      

I need to somehow get new_type as a string using the typeid, but if I use:

typeid(value)

      

It will return int instead of new_type.

Is there a way to return new_type as a string?

Thank!

+3


source to share


1 answer


typedef

are not their own types. Think of it as an alias for the original type.

"Is there a way to return new_type as a string?"

Since this is not the real type, it does not.




Remember that in typeid()

there , which means that it should always return the same ID to (effectively) the same type. id

The only thing I can think of to achieve what you want is creating your own wrapper class

/ struct

that behaves exactly like int

. But I doubt it's worth the effort.

+4


source







All Articles