C++: Identify type of an object [duplicate]
Possible Duplicate:
Finding the type of an object in C++
... Without using some kind of magic value ID? Are there any language features or maybe some techniques tha开发者_C百科t allow me to do that?
Why would you want to do that ?? In any case, just given a void * it is not possible to find out what type the object is atleast in C++. The QueryInterface pattern came into existense for this and other reasons in the COM model.
There's always typeid
. But what exactly are you trying to do? The
results of typeid( object ).name()
are implementation specified, and
whether they're useful for what you're trying to do or not depends on
what you are trying to do, and which implementation you're using. (You
can use a wrapper around typeid( object )
as a key into a map.)
精彩评论