• <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麻豆| 一本久久综合亚洲鲁鲁五月天| 热re99久久精品国99热| 国产巨作麻豆欧美亚洲综合久久| 国内精品久久久久影院网站| 久久九九兔免费精品6| 久久亚洲精品视频| 精品久久久久久国产潘金莲| 久久久久久久久久久免费精品| 伊人情人综合成人久久网小说 | 久久国产精品一区二区| 久久国产成人精品国产成人亚洲| 青青草原综合久久大伊人| 国产精品99精品久久免费| 久久亚洲中文字幕精品一区| 国产精品免费看久久久香蕉| 性色欲网站人妻丰满中文久久不卡| 亚洲人成电影网站久久| 秋霞久久国产精品电影院| 无码国内精品久久人妻| 一本久久a久久精品综合香蕉| 久久亚洲国产欧洲精品一| 国产综合精品久久亚洲| 色综合久久综合中文综合网| 久久精品二区| AAA级久久久精品无码区| 99久久国产热无码精品免费| 色综合久久综合中文综合网| 亚洲午夜久久久影院伊人| 亚洲精品tv久久久久久久久| 久久一本综合| 久久99精品国产麻豆婷婷| 久久久无码人妻精品无码| 国产综合久久久久| 婷婷伊人久久大香线蕉AV| 久久国产色AV免费观看| 99久久久精品免费观看国产| 91久久精品91久久性色|