raychenv / blog

my simple blog
1 stars 0 forks source link

Functor #353

Open raychenv opened 1 year ago

raychenv commented 1 year ago

仿函数

// this is a functor
struct add_x {
  add_x(int val) : x(val) {}  // Constructor
  int operator()(int y) const { return x + y; }

private:
  int x;
};

https://stackoverflow.com/questions/356950/what-are-c-functors-and-their-uses https://zhuanlan.zhihu.com/p/75353199