本文介绍了临时绑定到C ++标准中的成员使用期限语句的要点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在此问题用户 Happy Mittal 引用C ++ 03的第12.2.5节标准:在构造函数的ctor-initializer(12.6.2)中临时绑定到引用成员,直到构造函数退出 。In this question user Happy Mittal quotes section 12.2.5 of C++03 Standard: A temporary bound to a reference member in a constructor’s ctor-initializer (12.6.2) persists until the constructor exits.这怎么能有用呢?我的意思是一旦构造函数退出临时获取被销毁,但引用保持绑定 - 现在到一个已经销毁的对象。How can that be useful anyway? I mean once the constructor exits the temporary gets destroyed, but the reference remains bound - now to an already destroyed object.这么仔细指定临时生命周期的意义if在外部对象的整个生命周期中还有一个悬挂的参考? What's the point of so carefully specifying the temporary lifetime if there's still a dangling reference for the whole lifetime of the outer object? In which scenario can this behavior be useful?推荐答案将引用成员绑定到死对象是没有用的,但是在这种情况下,绑定到引用的正常临时生命周期扩展不适用是有用的。It is not useful to have a reference member bound to a dead object, but it is useful to be clear that "normal" temporary lifetime extension when bound to a reference doesn't apply in this case.它还指定临时生命期扩展,在ctor初始化器中:它被扩展到ctor的结尾,而不是在ctor主体执行之前死亡。除非在整个点执行ctor的聪明类中,这将是没有用的,并且正确地避免了这种类型的(ab)使用。It also specifies temporary lifetime extension that applies specially in the ctor initializer: it's extended to the end of the ctor rather than dying before the ctor body executes. This would not be useful except in "clever" classes whose whole point is executing the ctor, and this type of (ab)use is rightly avoided.我知道没有后者的真实世界的例子,但它让我类似于析构函数不是默认打破了在他们的生活中聪明的类和如何使用它们。这确实有现实世界的用途,并且出现讨论如何处理C ++ 0x中的dtors的默认语义。I know of no real world examples of the latter, but it strikes me akin to having destructors nothrow by default broke classes that were "clever" in their lifetime and how they were used. This did have real world uses and came up in discussions about how to handle the default semantics of dtors in C++0x. 这篇关于临时绑定到C ++标准中的成员使用期限语句的要点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-19 03:25