<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 67  文章 - 79  trackbacks - 0
    <2008年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(1)

    隨筆檔案

    文章檔案

    相冊

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    GCC4.3 開始了c++0x的實現(xiàn) 新的基本庫和語言特性
    下面是我對于shared_ptr的理解所寫的sample同時還用到了Variadic templates
    #include <c++0x_warning.h>
    #include 
    <tr1/array>
    #include 
    <tr1/tuple>
    #include 
    <tr1/memory>
    #include 
    <tr1/functional>
    #include 
    <string>
    #include 
    <iostream>
    #include 
    <typeinfo>

    using namespace std;
    using namespace tr1;

    typedef std::tr1::shared_ptr
    <char> char_p;
    typedef std::tr1::shared_ptr
    <wchar_t> wchar_tp;
    typedef std::tr1::shared_ptr
    <short> short_p;
    typedef std::tr1::shared_ptr
    <int> int_p;
    typedef std::tr1::shared_ptr
    <long> long_p;
    typedef std::tr1::shared_ptr
    <float> float_p;
    typedef std::tr1::shared_ptr
    <double> double_p;

    class sample : public std::tr1::enable_shared_from_this<sample> {
    private:
        std::string m_value;
    protected:
        typedef std::tr1::enable_shared_from_this
    <sample> base;

    public:
        
        
    void setValue(const std::string& o){m_value=o;}
        std::string getValue(){
    return m_value;}
        sample() {
        }
        sample(
    const sample& other) :
            base(other) {
            m_value
    =other.m_value;
        }
        sample(std::string s):m_value(s){}
        sample(
    const char* buff,size_t len):m_value(buff,len){}
        sample
    & operator =(const sample& other) {
            base::operator 
    =(other); // explicit call to assignment operator
            m_value=other.m_value;
            
    return *this;
        }

    };
    typedef std::tr1::shared_ptr
    <sample> sample_p;

    template
    <typename T,typename Args>
    std::tr1::shared_ptr
    <T> New(Args args) {
    return std::tr1::shared_ptr<T>(new T(args));
    }

    int main(int argc, char **argv) {

        int_p ip1
    =New<int>(10);
        int_p ip2
    =New<int>();
        int_p ip3
    =New<int>(*ip1);
        long_p ipl1
    =New<long>();
        cout
    <<"ip1:"<<*ip1<<'\n';
        cout
    <<"ip2:"<<*ip2<<'\n';
        cout
    <<"ip3:"<<*ip3<<'\n';
        
        std::string s
    ="Welcome C++0x!";
        sample_p sp1
    =New<sample>();
        cout
    <<"This is sp1 "<<sp1->getValue()<<'\n';
        
        sample_p sp2
    =New<sample>("This is sp2");
        cout
    <<"This is sp2 "<<sp2->getValue()<<'\n';
        
        sample_p sp3
    =New<sample>(s.c_str(),s.size());
        sample_p sp4
    =New<sample>(*sp3);
        sample_p sp5(sp3);
        
        sp3
    ->setValue("Now it is sp3");
        
        cout
    <<"This is sp3 "<<sp3->getValue()<<'\n';
        cout
    <<"This is sp4 "<<sp4->getValue()<<'\n';
        cout
    <<"This is sp5 "<<sp5->getValue()<<'\n';
        

        
    return 0;
    }


    posted on 2008-05-22 16:05 zarra 閱讀(213) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 午夜时刻免费入口| 最新亚洲成av人免费看| 国产免费不卡v片在线观看| 亚洲国产精品无码久久一线| 五月天国产成人AV免费观看| 亚洲国产精品丝袜在线观看| 精品亚洲福利一区二区| 四虎影视在线永久免费观看| 亚洲乱码日产精品一二三| 免费毛片在线看片免费丝瓜视频| 97久久国产亚洲精品超碰热| 欧美男同gv免费网站观看 | 亚洲精品V天堂中文字幕| 岛国av无码免费无禁网站| 亚洲AV男人的天堂在线观看| 天天天欲色欲色WWW免费| 国产亚洲精品美女久久久久| ZZIJZZIJ亚洲日本少妇JIZJIZ| 久久一区二区三区免费| 久久精品国产亚洲香蕉| 亚洲黄色免费网址| 在线精品亚洲一区二区| 九月婷婷亚洲综合在线| 国产一级婬片A视频免费观看| 亚洲高清在线观看| 美女视频黄的全免费视频网站| 亚洲国产美女精品久久久| 亚洲 综合 国产 欧洲 丝袜| 两个人日本免费完整版在线观看1| 亚洲国产精品久久久久| 成人au免费视频影院| 国产亚洲精品美女| 亚洲第一精品在线视频| 拍拍拍又黄又爽无挡视频免费| 日韩免费高清一级毛片| 亚洲成a人片在线观看无码 | 免费国产真实迷j在线观看| 国产综合免费精品久久久| 亚洲一区二区三区久久久久| 国产免费私拍一区二区三区| 国产成人无码区免费内射一片色欲 |