返回对象时使用std ::移动
如果我有以下功能:
MyObject Process(std::string par1, int par2){
MyObject message;
// Do some processing here
return message;
}
可以这样实现:
MyObject Process(std::string par1, int par2){
MyObject message;
// Do some processing here
return std::move(message);
}
两者之间有什么区别? (我有一个概念是第二个概念不会复制对象消息
,而只是移动它,但是由于Message> Message
函数范围正在完成,所以这代表了什么?
If I have the following function:
MyObject Process(std::string par1, int par2){
MyObject message;
// Do some processing here
return message;
}
Can this be implemented like this:
MyObject Process(std::string par1, int par2){
MyObject message;
// Do some processing here
return std::move(message);
}
And what is the difference between both? (I have the notion that the second one will not copy the object message
but just move it, but since message
function scope is finishing, what does this represent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论