15-07-03.cpp
来自「more efftive 代码」· C++ 代码 · 共 42 行
CPP
42 行
#include <iostream>#include <functional>#include <iterator>#include <algorithm>#include <vector>using namespace std;struct Operation { virtual double eval(double) = 0;};struct Square : public Operation { double eval(double x) { return x * x; }};struct Negate : public Operation { double eval(double x) { return -x; }};int main(){ vector<Operation*> operations; vector<double> operands; operations.push_back(new Square); operations.push_back(new Square); operations.push_back(new Negate); operations.push_back(new Negate); operations.push_back(new Square); operands.push_back(1); operands.push_back(2); operands.push_back(3); operands.push_back(4); operands.push_back(5); transform(operations.begin(), operations.end(), operands.begin(), ostream_iterator<double>(cout, "\n"), mem_fun(&Operation::eval));}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?