它返回没有副本的大对象? [英] It returns large obiject without copy?

查看:71
本文介绍了它返回没有副本的大对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有

vector<vector<MyStruct>> findPred(vector<vector<MyStruct>> &inputVec)
{
    vector<vector<MyStructs>> result;
////
    Filling list of list of struct;
////
    return result;
}

int main()
{
  vector<vector<MyStructs>> ret = findPred(inputVec);
}


在这种情况下是否返回调用副本和临时对象?

In this situation returns call copy and temporary objects or not?

推荐答案

这取决于您使用的编译器是否支持C ++ 11 r值引用和移动构造函数。

This depends on if the compiler you are using supports C++11 r-value references and move constructors.

但是现在这应该调用移动构造函数和main中的向量将从findPred中的向量中获取内存。

But these days, this should invoke the move constructor and the vector in main will just take the memory from the vector in findPred.


这篇关于它返回没有副本的大对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆