這在STL頭文件中定義:std ::更大<int>()期望0個參數(或1個參數),2個提供,爲什麼?
template<typename _Tp>
struct greater : public binary_function<_Tp, _Tp, bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{ return __x > __y; }
};
我寫了下面只有一行簡單的代碼:
cout << (std::greater<int>(3, 2)? "TRUE":"FALSE") << endl;
它不編譯。錯誤訊息是:
C:\Qt\Tools\mingw482_32\i686-w64-mingw32\include\c++\bits\stl_function.h:222: std::greater<int>::greater()
struct greater : public binary_function<_Tp, _Tp, bool>
^
C:\Qt\Tools\mingw482_32\i686-w64-mingw32\include\c++\bits\stl_function.h:222: note: candidate expects 0 arguments, 2 provided
C:\Qt\Tools\mingw482_32\i686-w64-mingw32\include\c++\bits\stl_function.h:222: std::greater<int>::greater(const std::greater<int>&)
C:\Qt\Tools\mingw482_32\i686-w64-mingw32\include\c++\bits\stl_function.h:222: note: candidate expects 1 argument, 2 provided
怎麼了? 編譯器當然是minGW(GCC)。
這是我的代碼的簡化版本。事實上,我在我複雜的排序算法中使用std :: greater。
你試圖構造一個對象有兩個參數,但類沒有構造函數... –