• <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庫等
             
            日本久久久久久中文字幕| 久久人人爽人人人人爽AV | 亚洲国产精品狼友中文久久久| 国产2021久久精品| 久久热这里只有精品在线观看| 少妇内射兰兰久久| 丰满少妇人妻久久久久久4| 日日狠狠久久偷偷色综合免费| 久久国产劲爆AV内射—百度| 精品国产福利久久久| 7777精品伊人久久久大香线蕉| 成人久久久观看免费毛片| 四虎影视久久久免费| 精品综合久久久久久97超人| AV无码久久久久不卡蜜桃| 国产精品99久久精品爆乳| 日产精品99久久久久久| 亚洲人成无码www久久久| 久久精品国产99国产电影网| 热99RE久久精品这里都是精品免费| 色综合久久88色综合天天| 久久久精品人妻一区二区三区蜜桃| 国产亚洲色婷婷久久99精品91| 久久久无码精品亚洲日韩按摩 | 久久精品国产亚洲av水果派| 香蕉99久久国产综合精品宅男自 | 狠狠色丁香久久婷婷综合_中| 久久久久久一区国产精品| 91精品国产9l久久久久| 久久综合精品国产二区无码| 久久精品国产精品亚洲精品| 武侠古典久久婷婷狼人伊人| 久久久久亚洲AV无码专区桃色 | 亚洲国产二区三区久久| 国产精品天天影视久久综合网| 少妇高潮惨叫久久久久久| 亚洲午夜久久久久妓女影院 | 无码精品久久久久久人妻中字| 久久午夜福利无码1000合集| 久久精品一本到99热免费| 亚洲∧v久久久无码精品|