mem_fun例子-创新互联

创新互联专注于企业营销型网站、网站重做改版、淮北网站定制设计、自适应品牌网站建设、html5商城网站定制开发、集团公司官网建设、成都外贸网站建设公司、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为淮北等各大城市提供网站开发制作服务。>// functional_mem_fun.cpp // compile with: /EHsc#include <vector> #include<functional> #include<algorithm> #include<iostream> #include<ext/functional> using namespace std; class StoreVals { int val; public: StoreVals() { val= 0; } StoreVals(int j) { val = j; } bool display() { cout << val << " "; return true; } int squareval() { val *= val; return val; } int lessconst(int k) {val -= k; return val; } }; int main( ) { vector<StoreVals *> v1; StoreVals sv1(5); v1.push_back(&sv1); StoreVals sv2(10); v1.push_back(&sv2); StoreVals sv3(15); v1.push_back(&sv3); StoreVals sv4(20); v1.push_back(&sv4); StoreVals sv5(25); v1.push_back(&sv5); cout<< "The original values stored are:" ; for_each(v1.begin(), v1.end(), mem_fun<bool, StoreVals>(&StoreVals::display)); cout<< endl; // Use of mem_fun calling member function through a pointer // square each value in the vector using squareval () for_each(v1.begin(), v1.end(), mem_fun<int, StoreVals>(&StoreVals::squareval)); cout<< "The squared values are:" ; for_each(v1.begin(), v1.end(), mem_fun<bool, StoreVals>(&StoreVals::display)); cout<< endl; // Use of mem_fun1 calling member function through a pointer // subtract 5 from each value in the vector using lessconst () for_each(v1.begin(), v1.end(), bind2nd (__gnu_cxx::mem_fun1<int, StoreVals,int>(&StoreVals::lessconst), 5)); cout<< "The squared values less 5 are:" ; for_each(v1.begin(), v1.end(), mem_fun<bool, StoreVals>(&StoreVals::display)); cout<< endl; }

分享名称:mem_fun例子-创新互联
文章路径:https://www.cdcxhl.com/article44/cceoee.html

成都网站建设公司_创新互联,为您提供企业网站制作App开发企业建站网站设计公司域名注册外贸建站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

外贸网站制作