我不明白我在最后一行遇到的编译器错误:
#include <iostream>
#include <algorithm>
struct X{
int number;
};
bool same_number_X(const int & a, const X & b)
{ return a == b.number; }
bool same_number_int(const int & a, const int & b)
{ return a == b; }
int main(){
std::vector<int> vec1{1,2,3};
std::vector<int> vec2{2,3,1};
std::vector<X> vec3{{2},{3},{1}};
std::cout << std::is_permutation(vec1.begin(), vec1.end(), vec2.begin(), same_number_int);
std::cout << std::is_permutation(vec1.begin(), vec1.end(), vec3.begin(), same_number_X);
}
你可以在这里看到错误 它说
In instantiation of 'typename std::iterator_traits<_InputIterator>::difference_type std::count_if(_IIter, _IIter, _Predicate) [with _IIter = __gnu_cxx::__normal_iterator<X*, std::vector<X> >; _Predicate = std::_Bind<bool (*(std::_Placeholder<1>, int))(const int&, const X&)>; typename std::iterator_traits<_InputIterator>::difference_type = long int]':
c++/4.7/bits/stl_algo.h:4367:37: required from 'bool std::is_permutation(_FIter1, _FIter1, _FIter2, _BinaryPredicate) [with _FIter1 = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _FIter2 = __gnu_cxx::__normal_iterator<X*, std::vector<X> >; _BinaryPredicate = bool (*)(const int&, const X&)]'
source.cpp:23:90: required from here
c++/4.7/bits/stl_algo.h:4681:2: error: no match for call to '(std::_Bind<bool (*(std::_Placeholder<1>, int))(const int&, const X&)>) (X&)'
任何人都可以用非编译器的话解释/解决它吗?:-)