问题描述
#include <utility>
#include <vector>
using namespace std;
std::pair<std::size_t,std::size_t> func(const std::vector<int>& numbers,int target) {
for(std::size_t i =0; i < numbers.size(); i++)
{
for(std::size_t j = i; j < numbers.size(); j++)
{
if(numbers[i] + numbers[j] == target)
return std::make_pair<std::size_t,std::size_t>(i,j);
}
}
return std::make_pair<std::size_t,std::size_t>(0,0);
}
错误:
test.cpp: In function ‘std::pair<long unsigned int,long unsigned int> func(const std::vector<int>&,int)’:
test.cpp:12:62: error: no matching function for call to ‘make_pair<std::size_t,std::size_t>(std::size_t&,std::size_t&)’
return std::make_pair<std::size_t,j);
^
In file included from /usr/include/c++/7/utility:70:0,from test.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:524:5: note: candidate: template<class _T1,class _T2> constexpr std::pair<typename std::__decay_and_strip<_Tp>::__type,typename std::__decay_and_strip<_T2>::__type> std::make_pair(_T1&&,_T2&&)
make_pair(_T1&& __x,_T2&& __y)
^~~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:524:5: note: template argument deduction/substitution failed:
test.cpp:12:62: note: cannot convert ‘i’ (type ‘std::size_t {aka long unsigned int}’) to type ‘long unsigned int&&’
return std::make_pair<std::size_t,j);
^
当我们清楚地提到模板化 unsigned long int
中的类型以及 pair
和 i
的数据类型时,为什么它试图用 j
代替?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)