operator() 的使用
operator() 的使用
=========================
operator()是函数调用操作符! STL中的各种functor就是重载它实现的.
举例(1):
class test { void operator()(int x) { cout<<x<<endl; } } int main() { test t; t(10); return 0; }
举例(2):
using namespace std; class Function { public: double operator()(double x) { return 2*x; } }; int main() { Function myFunc; cout<<myFunc(1.0)<<endl; system("pause"); }
---- THE END
浙公网安备 33010602011771号