Binding temporary to const reference in c'tor initializer list

元气小坏坏 提交于 2019-12-04 01:05:40

I have tried this with MS VS 2010, and it gives me the output also gives warning during compile:

warning C4413: 'bar::ref' : reference member is initialized to a temporary that doesn't persist after the constructor exits

foo c'tor
bar c'tor
foo d'tor
Press any key to continue . . .

It seems that MS VS 2010 implements specification correctly. I agree that it is a bug for g++.

EDIT: ref should be initialized in constructor`s initialize list.

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