Uniform initialization of references

前端 未结 1 929
一生所求
一生所求 2021-02-04 03:43

I am currently trying to understand the new uniform initialization of C++0x. Unfortunately, I stumpled over using uniform initialization of references. Example:

         


        
相关标签:
1条回答
  • 2021-02-04 04:19

    According to N2672 the paragraph 8.5.4.4 should say:

    Otherwise, if T is a reference type, an rvalue temporary of the type referenced by T is list-initialized, and the reference is bound to that temporary. [ Note: As usual, the binding will fail and the program is ill-formed if the reference type is an lvalue reference to a non-const type. ]

    which (if I understand it correctly) means uniform initialization of references binds them to new anonymous instances, so it seems to me it's pretty useless. That still does not explain why one works and the other does not; they should behave the same (unless Y has some explicit constructors).

    0 讨论(0)
提交回复
热议问题