functors.cpp
来自「C++高级编程这本书所附的源代码」· C++ 代码 · 共 35 行
CPP
35 行
#include <string>using namespace std;class FunctionObject{public: int operator() (int inParam); // function-call operator void operator() (string& str) {} int aMethod(int inParam); // normal method};//Implementation of overloaded function-call operatorint FunctionObject::operator() (int inParam){ return (inParam * inParam);}// Implementation of normal methodint FunctionObject::aMethod(int inParam){ return (inParam * inParam);}int main(int argc, char** argv){ int x = 3, xSquared, xSquaredAgain; FunctionObject square; xSquared = square(x); // Call the function-call operator xSquaredAgain = square.aMethod(x); // Call the normal method return (0);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?