typeid运算符返回的对象的生存期是多少? [英] What's the lifetime of the object returned by typeid operator?

查看:125
本文介绍了typeid运算符返回的对象的生存期是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我呼叫typeid并检索返回的type_info的地址:

If I call typeid and retrieve the address of returned type_info:

const type_info* info = &( typeid( Something ) );

typeid返回的对象的生存期是多少?指向该对象的指针将保持多长时间?

what's the lifetime of the object returned by typeid and how long will the pointer to that object remain valid?

推荐答案

无论实现如何实现,typeid表达式的结果都是左值,并且这些左值所引用的对象的生存期必须持续到操作结束.程序.

However the implementation implements them, the results of typeid expressions are lvalues and the lifetime of the objects that those lvalues refer to must last until the end of the program.

根据ISO/IEC 14882:2003 5.2.8 [expr.typeid]:

From ISO/IEC 14882:2003 5.2.8 [expr.typeid]:

typeid表达式的结果是一个左值[...]左值所引用的对象的生存期一直延伸到程序的末尾.

The result of a typeid expression is an lvalue [...] The lifetime of the object referred to by the lvalue extends to the end of the program.

这篇关于typeid运算符返回的对象的生存期是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆