这是我的代码“更大的”仿函数会产生编译错误
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
/*
struct greater
{template<class T>
bool operator()(T const &a, T const &b) const { return a > b; }
};*/
//std::sort(numbers.begin(), numbers.end(), greater());
int main(){
vector<int,::greater<int>()> a;
int x;
while (cin >> x)
a.push_back(x);
sort(a.begin(),a.end());
for (int b : a){
cout << b << endl;
}
return 0;
}
这是为什么错误?
map<int,int,::greater<int>()> a;
我已经看到了一些博客,他们可以通过,但我不能 我想知道答案
请注意,您的注释类不是一个模板,但它的一个方法是。因此,你不能有更大的类型,只是“更大”。 – MSalters