Functor (Function Object)

xiaoxiao2021-03-06  104

#include #include #include #include using namespace std; template class Add {private: type number; public: Add (type initv): number (initv) { CONST TYPE & OPERATOR () (Type & Elem) const {elem = number; returnide;}};

INT main () {list coll; for (INT i = 0; i <20; i) {coll.push_front (i); coll.push_back (i);} transform (Coll.begin (), Coll.end (), coll.begin (), add (10)); copy (coll.begin (), coll.end (), ostream_iterator (cout, ")); cout << Endl; for_each (coll.begin (), coll.end (), add (2)), copy (coll.begin (), coll.end (), ostream_iterator (cout, ")) COUT << Endl; cin.get (); return 0;}

转载请注明原文地址:https://www.9cbs.com/read-100547.html

New Post(0)