• <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庫等
             
            无码伊人66久久大杳蕉网站谷歌| 久久精品国产福利国产琪琪| 欧洲精品久久久av无码电影| 久久国产精品77777| 免费观看成人久久网免费观看| 久久精品视频91| 亚洲人成网亚洲欧洲无码久久 | 一本色道久久99一综合| .精品久久久麻豆国产精品 | 亚洲人成无码网站久久99热国产| 丁香色欲久久久久久综合网| 久久精品国产亚洲麻豆| 狠狠综合久久AV一区二区三区| 大美女久久久久久j久久| 亚洲狠狠婷婷综合久久久久| 久久国产热这里只有精品| 欧美丰满熟妇BBB久久久| 久久久久久亚洲精品无码| 精品久久久久久久久午夜福利| 一本色道久久综合狠狠躁篇 | 久久综合给合久久国产免费| 亚洲国产精品久久| 久久久久免费看成人影片| 久久精品国产亚洲av麻豆蜜芽| 国产高潮国产高潮久久久91 | 久久精品九九亚洲精品天堂| 亚洲国产另类久久久精品小说| 久久中文字幕视频、最近更新 | 亚洲国产成人精品91久久久 | 狠狠综合久久综合中文88| 久久国产色AV免费观看| 色欲久久久天天天综合网 | 国产精品久久久久久福利漫画| 国产A级毛片久久久精品毛片| 亚洲精品无码专区久久同性男| 99久久婷婷国产综合精品草原 | 久久成人小视频| 国产香蕉久久精品综合网| 久久九九兔免费精品6| 国内精品久久久久影院薰衣草| 久久天天躁夜夜躁狠狠躁2022|