• <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麻| 久久综合伊人77777| 国产精品一久久香蕉国产线看观看| 一本一本久久A久久综合精品| 色诱久久久久综合网ywww| 精品综合久久久久久97超人| 亚洲AⅤ优女AV综合久久久| 人妻无码αv中文字幕久久琪琪布| 国内精品伊人久久久久| 精品伊人久久久| 91精品国产91久久久久久青草| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 四虎久久影院| 精品久久久久久无码中文字幕一区| 99久久精品费精品国产| 伊人久久综合精品无码AV专区| 狠狠精品久久久无码中文字幕 | 99热成人精品免费久久| 亚洲精品无码久久一线| 久久无码av三级| 少妇高潮惨叫久久久久久| 国产激情久久久久影院| 国产精品久久波多野结衣| 亚洲中文字幕无码久久精品1| 99久久夜色精品国产网站| 久久99国产精品99久久| 成人国内精品久久久久一区| 欧美日韩成人精品久久久免费看| 91精品国产高清91久久久久久| 久久久久久久精品成人热色戒| 国产精品伊人久久伊人电影 | 亚洲色欲久久久综合网| 亚洲欧美久久久久9999| 日本久久久久久久久久| 久久久久人妻一区精品| 久久国产成人亚洲精品影院| 伊人色综合久久天天| 国产精品九九久久免费视频| 99久久99久久精品国产| 久久精品国产清自在天天线| 久久精品无码免费不卡|