开发者

Why is std::type_info noncopyable? Am I allowed to store it somewhere?

The std::type_info class is non-copyable. This makes it hard to store 开发者_开发问答it in an object for later use. What should I do?


There is a much better solution in C++11. A new copyable wrapper called std::type_index. You need to include header "typeindex" to use it.


You can store a pointer to a constant std::type_info object.


From MSDN and IBM online documentation:

The type_info class describes type information generated within the program by the compiler. Objects of this class effectively store a pointer to a name for the type. The type_info class also stores an encoded value suitable for comparing two types for equality or collating order. The encoding rules and collating sequence for types are unspecified and may differ between programs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜