我正在尝试制作一个比较第二项对的模板:
error: no matching function for call to ‘sort(std::vector<std::pair<int, int> >::iterator, std::vector<std::pair<int, int> >::iterator, <unresolved overloaded function type>)’
sort(sums.begin(), sums.end(), sortPairKey2<iipair,iipair>);
^
stp2mzn.cpp:409:63: note: candidates are:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from stp2mzn.cpp:9:
/usr/include/c++/4.8/bits/stl_algo.h:5447:5: note: template<class _RAIter> void std::sort(_RAIter, _RAIter)
sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
^
/usr/include/c++/4.8/bits/stl_algo.h:5447:5: note: template argument deduction/substitution failed:
stp2mzn.cpp:409:63: note: candidate expects 2 arguments, 3 provided
sort(sums.begin(), sums.end(), sortPairKey2<iipair,iipair>);
^
In file included from /usr/include/c++/4.8/algorithm:62:0,
from stp2mzn.cpp:9:
/usr/include/c++/4.8/bits/stl_algo.h:5483:5: note: template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)
sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
^
/usr/include/c++/4.8/bits/stl_algo.h:5483:5: note: template argument deduction/substitution failed:
stp2mzn.cpp:409:63: note: couldn't deduce template parameter ‘_Compare’
sort(sums.begin(), sums.end(), sortPairKey2<iipair,iipair>);
这样,如果我有一对配对,我仍然可以使用该功能。
但是当我在sort方法(from)中使用它时,我得到了:
typedef pair<int,int> iipair
其中T
。
当我pair<int,int>
代替@Override
public void onClick(View v) {
Intent intent = new Intent(context, SecondActivity.class);
//Add the position to the intent to be used in the second activity.
intent.putExtra("position", position);
context.startActivity(intent);
}
时,该功能正常运行。我不知道它的问题是什么。
谢谢!
答案 0 :(得分:4)
请尝试使用sortPairKey2<iipair>
代替sortPairKey2<iipair,iipair>
答案 1 :(得分:3)
两件事。
sortPairKey2<iipair, iipair>
,要么完全摆脱模板规范(你的编译器应该弄明白),要么只写sortPairKey2<iipair>