开发者

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

开发者 https://www.devze.com 2022-12-17 11:40 出处:网络
In C++ I can use typeid operator to retrieve the name of any polymorphic class: const char* name = typeid( CMyClass ).name();

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 开发者_如何学Goconst char* pointer available to my program?


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.


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

0

精彩评论

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