什段程式出:8 8
#include <iostream>
#include <vector>
#include <set>
using namespace std;
struct cmp{
bool operator()(int a,int b){
return a==b;
}
};
int main()
{
vector<it> x{8,4,6,1,4,2,7,8,8,5,8,8};
set<int,cmp> y(x.begin(),x.end());
for(auto iter=y.begin();iter!=y.end();iter++){
cout<<*iter<<" ";
}
return 0;
}
我知道 set 自定函式不能用,但我是好奇出的原因,根等於的定是:!comp(a, b) && !comp(b, a),那出要是:8 8 8 8 8 吧