gpt4 book ai didi

c++ - 错误 : no matching function for call to 'make_pair'

转载 作者:太空宇宙 更新时间:2023-11-04 14:59:27 25 4
gpt4 key购买 nike

<分区>

我想把两个局部变量成对并返回它,这是我的代码:

#include <utility>
class Foo {

};

class Bar {

};

std::pair<Foo, Bar> test() {
Foo foo;
Bar bar;
return std::make_pair<Foo, Bar>(foo, bar);
}

我得到了

main.cpp:92:10: error: no matching function for call to 'make_pair'   
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_pair.h:524:5:
note: candidate function not viable: no known conversion from 'Foo' to 'Foo &&' for 1st argument
make_pair(_T1&& __x, _T2&& __y)

如果我使用 return std::make_pair<Foo, Bar>(std::move(foo), std::move(bar)); ,编译成功。那我错过了什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com