What's the lifetime of memory pointed to typeinfo::name()?

 ̄綄美尐妖づ 提交于 2019-12-10 14:15:35

问题


In C++ I can use typeid operator to retrieve the name of any polymorphic class:

const char* name = typeid( CMyClass ).name();

How long will the string pointed to by the returned const char* pointer available to my program?


回答1:


As long as the class with rtti exists. So if you deal with single executable - forever. But for classes in a Dynamic Link Librariy it shifts a little. Potentially you can unload it.




回答2:


The memory returned by type_info::name() will be available for the application's lifetime.



来源:https://stackoverflow.com/questions/2109648/whats-the-lifetime-of-memory-pointed-to-typeinfoname

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!