简单记法:
仿函数不加括号时出现在模板定义<>中,加括号时出现在函数参数中
- 不加括号
priority_queue<int,vector<int>,greater<int>> v
(仿函数greater未加括号) - 加括号
class print
{
public:
void operator()(int n)
{
print("%d",n);
}
}
for_each(v.begin(), v.end(), print())
(仿函数print加了括号)
简单记法:
仿函数不加括号时出现在模板定义<>中,加括号时出现在函数参数中
priority_queue<int,vector<int>,greater<int>> v
class print
{
public:
void operator()(int n)
{
print("%d",n);
}
}
for_each(v.begin(), v.end(), print())
(仿函数print加了括号)