• <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庫等
             
            国产午夜福利精品久久| 久久91亚洲人成电影网站| 亚洲国产精品无码久久九九| 日韩欧美亚洲综合久久影院Ds| 久久国产亚洲精品| 久久亚洲精品成人av无码网站| 久久99热精品| 欧美激情精品久久久久久| 国产成人精品三上悠亚久久| 国产精品久久亚洲不卡动漫| 热久久国产欧美一区二区精品| 无码专区久久综合久中文字幕| 97精品国产97久久久久久免费| 久久午夜无码鲁丝片午夜精品| 日产精品久久久久久久性色| 久久精品国产精品亚洲人人| 久久精品国产乱子伦| 99久久精品久久久久久清纯| 伊色综合久久之综合久久| 久久国产精品一区二区| 亚洲精品午夜国产va久久| 国产成人综合久久综合| 亚洲人成无码www久久久| 久久国产高潮流白浆免费观看| 免费一级欧美大片久久网| 国产美女久久久| 欧美精品乱码99久久蜜桃| 久久99精品久久久久久9蜜桃| 色欲av伊人久久大香线蕉影院| 久久国产视屏| 99久久免费国产特黄| 亚洲中文字幕久久精品无码APP| 久久国产视屏| 91精品免费久久久久久久久| 伊人久久综合精品无码AV专区| 久久无码国产| 久久久久九国产精品| 91精品国产91久久久久久| 久久国产精品成人片免费| 亚洲精品国产字幕久久不卡| 久久99国产精品久久99小说|