Will member subobjects of local variables be moved too if returned from a function?

元气小坏坏 提交于 2019-11-30 07:21:54

When returning a subobject you can't elide its construction. Think of it this way: move and copy elision essentially amount to constructing the object in the place it would eventually be moved or copied to. This works for complete objects because there will be the appropriate space be set aside. It doesn't work with subobjects because you would construct the enclosing object. Even if this has the same size as the subobject, i.e. there is enough space, the enclosing object gets destroyed and may do funny things to the subobjects.

Effectively, this means that construction of the subject cannot be elided.

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