• <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庫等
             
            国产精品美女久久久网AV| 亚洲七七久久精品中文国产| 久久99国产综合精品| 久久91精品久久91综合| 久久精品亚洲乱码伦伦中文| 久久人人爽人人爽人人av东京热 | 久久久久99精品成人片三人毛片| 狠狠精品久久久无码中文字幕| 久久91精品国产91久| 秋霞久久国产精品电影院| 久久无码AV一区二区三区| 国内精品久久久久久野外| 久久久久久久精品成人热色戒| 91精品国产综合久久香蕉 | 国产成人精品久久综合| 亚洲国产另类久久久精品| 久久久久一级精品亚洲国产成人综合AV区 | 中文字幕久久精品 | 久久精品人人做人人爽97| 久久国产乱子伦精品免费午夜| 漂亮人妻被黑人久久精品| 久久国产亚洲精品| 久久久噜噜噜久久中文字幕色伊伊| 久久精品夜夜夜夜夜久久| 色偷偷久久一区二区三区| 国产精品亚洲综合久久| 日日狠狠久久偷偷色综合96蜜桃| 亚洲国产精品久久久久婷婷老年| 亚洲AV无码1区2区久久| 亚洲中文字幕无码久久2017| 亚洲七七久久精品中文国产| 伊人久久五月天| 亚洲七七久久精品中文国产 | 久久精品中文字幕无码绿巨人| 亚洲精品乱码久久久久久蜜桃不卡| 亚洲另类欧美综合久久图片区| 色综合久久中文字幕综合网| 免费一级做a爰片久久毛片潮| 日韩美女18网站久久精品| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 青青草原综合久久|