• <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热只有频精品66| 久久久久亚洲av无码专区喷水| 国产精品久久久久久久久鸭| 97超级碰碰碰碰久久久久| 亚洲性久久久影院| 久久精品国产亚洲AV无码偷窥| 亚洲综合婷婷久久| 久久精品国产亚洲AV不卡| 久久线看观看精品香蕉国产| 亚洲国产天堂久久久久久| 91精品国产高清91久久久久久 | 成人午夜精品久久久久久久小说 | 中文精品99久久国产 | 国产精品久久久久久久久| 久久中文字幕精品| 99久久99久久精品国产片果冻| 久久99精品久久久大学生| 国产日韩久久久精品影院首页| 人妻无码αv中文字幕久久| 日日狠狠久久偷偷色综合免费| 国产一级做a爰片久久毛片| 亚洲国产精品成人久久| 一本大道久久东京热无码AV| 国产精品99久久久久久宅男| 99久久免费国产精精品| 无码人妻久久一区二区三区免费 | 九九久久自然熟的香蕉图片| 婷婷久久综合| 久久久久亚洲?V成人无码| 伊人久久大香线焦综合四虎| 久久精品国产99国产精品澳门 | 久久er国产精品免费观看2| 久久国产欧美日韩精品| 欧美噜噜久久久XXX| 精产国品久久一二三产区区别| 久久99精品国产麻豆婷婷| 久久精品成人影院| 日日狠狠久久偷偷色综合0| 亚洲国产精品无码久久青草| 久久精品国产色蜜蜜麻豆|