這是function pointers using '<' as an operator的後續問題,它仍然沒有答案。標準操作符的函數指針
這是非常相似的答案代碼我發現這裏:Is it possible to get the function pointer of a built-in standard operator?
問:在上面的鏈接+
用作std::operator+
所以我爲什麼不能使用std::operator<
?
目的是不以較少的參數使用重載的功能可按取而代之的東西從std::library
template <typename T>
bool compare (T a,T b,bool (*compareFunction) (T ,T))
{
return compareFunction (a,b);
}
template <typename T>
bool compare (T a,T b)
{
return a<b;
}
bool m (int a ,int b)
{
return a<b;
}
int main()
{
int a=5,b=6;
/*
* This Works
*/
if (compare<int>(a,b,m))
cout<<"Sucess";
else
cout<<"Post this in stack overflow ";
/*
* This also Works
*/
if (compare<int>(a,b))
cout<<"Sucess";
else
cout<<"Post this in stack overflow ";
/*
* Adding this gives compile error.
*/
if (compare<int> (a,b,&std::operator<))
cout<<"sucess";
else
cout<<"Post in Stackoverflow ";
return 0;
}
誰標記它重複din't甚至讀我的完整問題....我已經看到了你給我的鏈接..事實上,我已經在我的問題本身中提到它...但東西不是工作夥計... – PRP
從第二個鏈接:'內置操作符(內置類型)不是真正的操作員功能。所以你不能有指向它們的函數指針。' –
@PRP _「目標是不使用具有較少參數的重載函數,而是用std :: library中的某些東西替換」_有很好的參考用法來自(現在未鎖定)僞裝中提到的C++標準庫。看起來你正在尋找['std :: less()'](http://en.cppreference.com/w/cpp/utility/functional/less) –