創(chuàng)新互聯(lián)專注于企業(yè)營銷型網站、網站重做改版、淮北網站定制設計、自適應品牌網站建設、html5、商城網站定制開發(fā)、集團公司官網建設、成都外貿網站建設公司、高端網站制作、響應式網頁設計等建站業(yè)務,價格優(yōu)惠性價比高,為淮北等各大城市提供網站開發(fā)制作服務。>
// 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例子-創(chuàng)新互聯(lián)
文章路徑:http://www.chinadenli.net/article44/cceoee.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供企業(yè)網站制作、App開發(fā)、企業(yè)建站、網站設計公司、域名注冊、外貿建站
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容