• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Cpper
            C/C++高級工程師 Android高級軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語言 程序猿
            本篇主要說明boost function的使用例子
            設(shè)計頭文件:
            #include <boost/function.hpp>

            基本的function對象例子
            boost::function<int(const char*,&int)> f;
            代碼該函子對應(yīng)的函數(shù)其返回值為int類型,她有個2個參數(shù)分別為const char*和&int類型
            一個簡單的例子如下所示:
            #include <iostream>
            #include 
            <boost/function.hpp>

            inline 
            int Sum(const int a,const int b)
            {
                
            return a + b;    
            }

            int main()
            {   
                boost::function
            <int(const int,const int)> sum_ptr;
                sum_ptr 
            = &Sum;
                std::cout
            <<"1+2=:?"<<sum_ptr(1,2);
                system(
            "PAUSE");
                
            return EXIT_SUCCESS;
            }
            如果對應(yīng)的函數(shù)為類的成員函數(shù)則其使用例子可參考下面的說明:
            #include <iostream>
            #include 
            <boost/function.hpp>
            #include 
            <functional>

            struct Adder 
            {
                Adder(
            int val):value(val){}
                
            int Add(int x){return x*value;}
                
            int value;
            };

            int main()
            {   
                
            //! 對應(yīng)函數(shù)返回值int參數(shù)為int
                boost::function<int(int)>f;
                Adder add(
            7);
                
            //! 綁定成員函數(shù)到boost::function<>
                f = std::bind1st(std::mem_fun(&Adder::Add),&add);
                std::cout
            <<f(5)<<std::endl; 

                
                system(
            "PAUSE");
                
            return EXIT_SUCCESS;
            }
            對于仿函子則可以這樣做:
            #include <iostream>
            #include 
            <boost/function.hpp>
            #include 
            <functional>

            struct Div 
            {
                
            float operator()(int x, int y)const 
                {    
                   
            return((float)x)/y; 
                }
            };

            int main()
            {   
                
            //! 2
                boost::function<float(int,int)> div;
                div 
            = Div();
                std::cout
            <<div(1,2)<<std::endl;
                
                system(
            "PAUSE");
                
            return EXIT_SUCCESS;
            }
            //! ccsdu2004

            posted on 2010-08-14 18:42 ccsdu2009 閱讀(441) 評論(0)  編輯 收藏 引用 所屬分類: boost庫等
             
            久久久久久久女国产乱让韩| 日韩人妻无码一区二区三区久久99| 国内精品综合久久久40p| 久久强奷乱码老熟女网站| 久久狠狠爱亚洲综合影院| 色综合久久中文字幕无码| 77777亚洲午夜久久多喷| 人妻精品久久无码专区精东影业| 激情伊人五月天久久综合| 精品熟女少妇aⅴ免费久久| 久久人妻少妇嫩草AV蜜桃| 成人免费网站久久久| 人人狠狠综合88综合久久| 国产午夜福利精品久久2021 | 久久精品国产亚洲精品| 久久只有这精品99| 久久福利青草精品资源站免费| 一本一本久久a久久精品综合麻豆| 欧美精品久久久久久久自慰| 国内精品久久久久久久涩爱| 久久婷婷五月综合色高清| 欧美精品福利视频一区二区三区久久久精品 | A级毛片无码久久精品免费| 伊人色综合久久天天网| 伊人久久综合热线大杳蕉下载| 久久久久久久久久久久久久| 国产精品99久久不卡| 成人妇女免费播放久久久| 亚洲国产精品成人久久| 一本色道久久88综合日韩精品| 99久久国产综合精品网成人影院 | 色综合色天天久久婷婷基地 | 999久久久无码国产精品| 久久久亚洲欧洲日产国码是AV| 久久乐国产精品亚洲综合| 国产精品久久一区二区三区| 久久香蕉超碰97国产精品| 亚洲乱码中文字幕久久孕妇黑人| 91麻豆国产精品91久久久| 色综合久久夜色精品国产| 色欲综合久久躁天天躁|