C++
functor仿函数
重载函数调用(),可当作函数使用。
跟函数指针相比,能保存状态(即struct的private变量)
https://stackoverflow.com/questions/356950/what-are-c-functors-and-their-uses
`
template
struct plus {
T operator(const T &a, const T &b) const {return a + b};
//greater : functor greater
priority_queue<int, vector
`
explicit 修饰单参数构造函数
避免隐式转换
`
class A {
public:
A(int _a) : a(_a){}
private:
int a;
}
A a(1)
A b;
b = 1 // non-explicit pass 隐式调用了构造函数
b = 1 // with explicit compile error
`