开发者

C++: Identify type of an object [duplicate]

This question already has answers here: Closed 11 years ago.

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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜