• <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久久久久 | 青青热久久国产久精品 | 性色欲网站人妻丰满中文久久不卡| 日韩va亚洲va欧美va久久| 国产免费久久精品99re丫y| 日韩精品久久无码人妻中文字幕| 久久66热人妻偷产精品9| 亚洲国产二区三区久久| 亚洲va久久久久| 一本大道加勒比久久综合| 久久精品国产久精国产果冻传媒| 9久久9久久精品| 麻豆久久久9性大片| 国产99久久精品一区二区| 久久中文精品无码中文字幕| 日韩久久久久久中文人妻| 欧美精品丝袜久久久中文字幕 | 狠狠色综合网站久久久久久久高清| 1000部精品久久久久久久久| 日韩精品久久久久久久电影| 国产精品久久久久久福利漫画| 国产69精品久久久久APP下载| 超级碰久久免费公开视频| 丰满少妇人妻久久久久久| 国产精品99久久久精品无码| 国产精品成人99久久久久| 久久99国产精品二区不卡| 久久久无码精品亚洲日韩按摩| 精品久久久久久久国产潘金莲| 久久一区二区三区免费| 久久精品国产色蜜蜜麻豆| 日韩精品国产自在久久现线拍| 久久久国产精品亚洲一区| 色诱久久久久综合网ywww| 伊人久久大香线蕉av不卡| 狠狠色丁香久久婷婷综合_中 | 亚洲va久久久噜噜噜久久狠狠| 久久笫一福利免费导航| 亚洲国产精品无码久久久久久曰| 91精品观看91久久久久久| 青青青国产成人久久111网站|