• <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庫等
             
            国产精品久久久久免费a∨| 国产亚洲精久久久久久无码| 亚洲中文字幕伊人久久无码| 亚洲精品无码久久久久久| 久久亚洲精精品中文字幕| 丰满少妇人妻久久久久久4| 色综合久久天天综线观看| 久久国产精品一国产精品金尊 | 久久亚洲熟女cc98cm| 久久精品欧美日韩精品| 亚洲国产成人久久精品99| 国产精品久久久久9999高清| 久久无码国产| 国产精品无码久久四虎| 久久夜色精品国产网站| 久久久久久亚洲精品影院| 精品国产综合区久久久久久 | 亚洲国产精品久久久久久| 久久人妻少妇嫩草AV蜜桃| 色综合色天天久久婷婷基地| 99久久精品免费看国产一区二区三区| 久久精品视频网| 久久ZYZ资源站无码中文动漫 | 久久亚洲私人国产精品vA| 久久99国产精品久久99小说 | 狠狠精品久久久无码中文字幕| 欧美黑人激情性久久| 亚洲精品乱码久久久久久自慰| 亚洲人成网站999久久久综合 | 欧美一区二区三区久久综合| 久久亚洲国产成人影院| 久久综合视频网| 国产成人久久精品一区二区三区| 久久精品视频一| 精品综合久久久久久97| 亚洲国产精品无码久久| 国产成人久久精品一区二区三区| 精品国产乱码久久久久久人妻 | 麻豆精品久久久一区二区| 99久久99久久精品国产片| 国产精自产拍久久久久久蜜|