• <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 閱讀(443) 評論(0)  編輯 收藏 引用 所屬分類: boost庫等
             
            精品无码久久久久久国产| 久久精品无码专区免费| 亚洲第一极品精品无码久久 | 日本免费久久久久久久网站| 尹人香蕉久久99天天拍| 麻豆精品久久久久久久99蜜桃| 国产精品一区二区久久精品涩爱| 亚洲伊人久久大香线蕉综合图片| 色8久久人人97超碰香蕉987| 亚洲国产成人久久精品影视| 日本国产精品久久| 狠狠久久综合| 久久久久综合网久久| 久久影院综合精品| 精品久久久久久久国产潘金莲| 久久99国产精品久久99果冻传媒| 久久久久久久精品成人热色戒| yellow中文字幕久久网| 精品久久国产一区二区三区香蕉| 2020久久精品亚洲热综合一本| 国产精品嫩草影院久久| 国产精品成人99久久久久91gav| 久久免费高清视频| 亚洲天堂久久精品| 欧美亚洲国产精品久久久久| 一级做a爰片久久毛片毛片 | 日韩亚洲欧美久久久www综合网 | 久久久久国产精品| Xx性欧美肥妇精品久久久久久 | 91精品国产91久久| 欧美成人免费观看久久| 99蜜桃臀久久久欧美精品网站 | 精品久久久久久国产三级| 久久精品国产亚洲Aⅴ蜜臀色欲 | 亚洲伊人久久大香线蕉综合图片| 一本久久知道综合久久| 久久精品国产亚洲一区二区三区| 狠狠色丁香久久婷婷综合图片| 久久综合久久久| 欧美va久久久噜噜噜久久| 99久久精品无码一区二区毛片|