问题描述
#include <map>
#include <tuple>
int test(int x,int y){
std::map<std::tuple<int,int>,std::string> test_1;
std::tuple<int,int> test2;
test2 = make_tuple(x,y);
test_1.insert<std::pair<std::tuple<int,std::string>(test2,"string");
return test_1;
}
错误:
'return': 不能从 'std::mapstd::tuple
解决方法
您想返回 std::map<std::tuple<int,int>,std::string>
,但您已将返回类型写为 int
。
#include <map>
#include <tuple>
std::map<std::tuple<int,std::string> test(int x,int y){
std::map<std::tuple<int,std::string> test_1;
std::tuple<int,int> test2;
test2 = make_tuple(x,y);
test_1.insert<std::pair<std::tuple<int,std::string>(test2,"string");
return test_1;
}