指向 typeinfo::name() 的内存的生命周期是多少?

发布于 2024-08-18 15:16:02 字数 158 浏览 2 评论 0原文

在 C++ 中,我可以使用 typeid 运算符来检索任何多态类的名称:

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

返回的 const char* 指针指向的字符串对我的程序可用多久?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

執念 2024-08-25 15:16:02

只要带有 rtti 的类存在。因此,如果您处理单个可执行文件 - 永远。
但对于动态链接库中的类,情况会发生一些变化。您可能可以卸载它。

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.

☆獨立☆ 2024-08-25 15:16:02

type_info::name() 返回的内存将在应用程序的生命周期内可用。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文