List using with references, changes behavior when used as a member

房东的猫 提交于 2019-12-08 09:49:32

Aggregate initialization allows binding references to temporaries (and this causes lifetime extension). Your first example is aggregate initialization because node is an aggregate.

However, in a constructor member initializer list, it is ill-formed to bind a reference to a temporary (C++17 class.base.init/11). This is because there is no lifetime extension in that situation , and allowing it would inevitably produce a dangling reference. In the second example node is not an aggregate because it has a user-provided constructor.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!