• <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的使用例子
            設計頭文件:
            #include <boost/function.hpp>

            基本的function對象例子
            boost::function<int(const char*,&int)> f;
            代碼該函子對應的函數其返回值為int類型,她有個2個參數分別為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;
            }
            如果對應的函數為類的成員函數則其使用例子可參考下面的說明:
            #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()
            {   
                
            //! 對應函數返回值int參數為int
                boost::function<int(int)>f;
                Adder add(
            7);
                
            //! 綁定成員函數到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 閱讀(434) 評論(0)  編輯 收藏 引用 所屬分類: boost庫等
             
            77777亚洲午夜久久多喷| 中文成人无码精品久久久不卡| 色综合久久无码五十路人妻| 精品国产乱码久久久久久1区2区| 好久久免费视频高清| 久久综合视频网站| 一本一道久久综合狠狠老| 久久久久久久尹人综合网亚洲| 久久久久亚洲精品中文字幕| 久久精品九九亚洲精品| 久久激情五月丁香伊人| 996久久国产精品线观看| 婷婷久久综合| segui久久国产精品| 久久精品中文无码资源站 | 久久婷婷国产综合精品| 久久精品一区二区影院| 国产成人久久精品一区二区三区| 婷婷久久五月天| 久久se精品一区二区影院| www.久久热| 欧美黑人激情性久久| 中文字幕久久久久人妻| 免费无码国产欧美久久18| 香蕉久久夜色精品国产小说| 日韩精品久久久久久久电影蜜臀| 久久综合一区二区无码| 精品久久久久久无码免费| 91久久精品电影| 亚洲国产精品久久久久网站| 国内精品人妻无码久久久影院 | 国产999精品久久久久久| 久久精品亚洲一区二区三区浴池| 久久精品久久久久观看99水蜜桃| 久久亚洲欧洲国产综合| 久久精品无码av| 伊人久久大香线蕉精品不卡| 人人狠狠综合88综合久久| 九九精品久久久久久噜噜| 久久久一本精品99久久精品88| 午夜精品久久久久久99热|