日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C++零基礎(chǔ)教程之std:function函數(shù)包裝器

前言

C++中可調(diào)用對象的雖然都有一個比較統(tǒng)一的操作形式,但是定義方法五花八門,這樣就導(dǎo)致使用統(tǒng)一的方式保存可調(diào)用對象或者傳遞可調(diào)用對象時,會十分繁瑣。C++提供了std::function和std::bind統(tǒng)一了可調(diào)用對象的各種操作。不同類型可能具有相同的調(diào)用形式。使用前記得加上functional頭文件。

成都創(chuàng)新互聯(lián)從2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都網(wǎng)站設(shè)計、成都網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元深澤做網(wǎng)站,已為上家服務(wù),為深澤各地企業(yè)和個人服務(wù),聯(lián)系電話:028-86922220

包裝普通函數(shù)

 
 
 
  1. #include  
  2. #include  
  3. #include  
  4. using namespace std; 
  5. int Max(int a, int b)  
  6.     return a > b ? a : b; 
  7. void print()  
  8.     cout << "無參無返回值" << endl; 
  9. int main() 
  10.   function funMax(Max); 
  11.     cout << funMax(1, 2) << endl; 
  12.     function funPrint(print); 
  13.     print(); 
  14.     printData(funMax, 1, 2); 
  15.   return 0; 

包裝類的靜態(tài)方法

 
 
 
  1. #include  
  2. #include  
  3. #include  
  4. using namespace std; 
  5. class Test  
  6. public: 
  7.     static void  print(int a, int b)  
  8.     { 
  9.         cout << a + b << endl; 
  10.     } 
  11.     void operator()(string str)  
  12.     { 
  13.         cout << str << endl; 
  14.     } 
  15.     operator FuncPTR()  
  16.     { 
  17.         return print; 
  18.     } 
  19. }; 
  20. int main()  
  21.     //包裝類的靜態(tài)方法 
  22.     function sFunc = Test::print; 
  23.     sFunc(1, 2); 
  24.     return 0; 

包裝仿函數(shù)

 
 
 
  1. #include  
  2. #include  
  3. #include  
  4. using namespace std; 
  5. class Test  
  6. public: 
  7.     void operator()(string str)  
  8.     { 
  9.         cout << str << endl; 
  10.     } 
  11. }; 
  12. int main()  
  13.     //包裝仿函數(shù) 
  14.     Test test; 
  15.     function funTest = test; 
  16.     test("仿函數(shù)"); 
  17.     return 0; 

包裝轉(zhuǎn)換成函數(shù)指針的對象 (operator的隱式轉(zhuǎn)換)

 
 
 
  1. #include  
  2. #include  
  3. #include  
  4. using namespace std; 
  5. using FuncPTR = void(*)(int, int); 
  6. class Test  
  7. public: 
  8.   static void  print(int a, int b)  
  9.     { 
  10.         cout << a + b << endl; 
  11.     } 
  12.     operator FuncPTR()  
  13.     { 
  14.         return print; 
  15.     } 
  16. }; 
  17. int main()  
  18.     //包裝轉(zhuǎn)換成函數(shù)指針的對象  (operator的隱式轉(zhuǎn)換) 
  19.     Test object; 
  20.     function funOPE = object; 
  21.     funOPE(2, 3); 
  22.     return 0; 

新聞標(biāo)題:C++零基礎(chǔ)教程之std:function函數(shù)包裝器
路徑分享:http://www.5511xx.com/article/dhgedgo.html