這是我的代碼「更大的」仿函數會產生編譯錯誤
#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