<分区>
我想把两个局部变量成对并返回它,这是我的代码:
#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));
,编译成功。那我错过了什么?