C++ 大函子不';行不通
这是代码C++ 大函子不';行不通,c++,templates,generics,stl,functor,C++,Templates,Generics,Stl,Functor,这是代码 #include <iostream> #include <algorithm> #include <functional> using namespace std; int main() { int a = 1; int b=2; if(greater<int>(a,b)) cout<<"YES"; else cout<<"NO"; } #包括
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
int a = 1;
int b=2;
if(greater<int>(a,b))
cout<<"YES";
else
cout<<"NO";
}
#包括
#包括
#包括
使用名称空间std;
int main()
{
INTA=1;
int b=2;
如果(大于(a,b))
不能用下面的方法写
if(greater<int>()(a,b))
if(更大的()(a,b))
要比较值,类std::greater使用其运算符函数std::greater
的比较功能通过其运算符()
或函数调用运算符完成
greater<int>(a,b)
它的工作方式如下:
int a = 1;
int b=2;
greater<int> g;
if(g(a,b))
cout<<"YES";
else
cout<<"NO";
inta=1;
int b=2;
大g;
如果(g(a,b))
coutstd::greater
是一个类模板。您需要首先创建一个实例,即std::greater()(a,b)如果李察回答了你的问题,请考虑通过点击旁边的灰色复选标记来接受答案。这会让其他人知道你不再积极寻找一个改进的解决方案,并在堆栈溢出上为你赢得新的徽章。
int a = 1;
int b=2;
greater<int> g;
if(g(a,b))
cout<<"YES";
else
cout<<"NO";