• <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 閱讀(440) 評論(0)  編輯 收藏 引用 所屬分類: boost庫等
             
            精品国产乱码久久久久久呢| 久久久一本精品99久久精品66| 久久精品国产AV一区二区三区| 色狠狠久久综合网| 俺来也俺去啦久久综合网| 97超级碰碰碰碰久久久久| 国产毛片久久久久久国产毛片| 久久青青草视频| 久久国产精品无码一区二区三区| 久久久中文字幕日本| 99久久国产综合精品麻豆| 久久精品成人一区二区三区| 国产午夜久久影院| 国产午夜精品久久久久免费视| 国产精品成人99久久久久| 久久这里的只有是精品23| 一本大道久久a久久精品综合 | 日韩精品久久无码人妻中文字幕| 亚洲精品高清久久| 久久久噜噜噜久久中文字幕色伊伊| 青青草原综合久久| 99久久无码一区人妻| 久久国产精品成人片免费| 久久中文字幕人妻丝袜| 一级做a爰片久久毛片毛片| 国产—久久香蕉国产线看观看 | 久久综合给合久久狠狠狠97色| 99久久人人爽亚洲精品美女| 久久ZYZ资源站无码中文动漫| 久久久久久久波多野结衣高潮| 久久久久亚洲?V成人无码| 久久精品草草草| 国产精品久久网| 婷婷久久综合九色综合98| 久久AV高清无码| 国产精品一区二区久久| 久久综合丁香激情久久| 日本福利片国产午夜久久| 国产亚洲精品自在久久| 99久久国产热无码精品免费| 99久久久国产精品免费无卡顿|