• <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>

            08年04月18日

            Posted on 2008-04-18 18:14 RichardHe 閱讀(189) 評論(2)  編輯 收藏 引用
            了解了通過模板來使用單件模式
            *.h
            template <typename T> class CEGUIEXPORT Singleton
            {
            protected:
                static T* ms_Singleton;

            public:
                Singleton( void )
                {
                    assert( !ms_Singleton );
                    ms_Singleton = static_cast<T*>(this);//這個this是指的什么???不能理解,誰能幫我說明下么?謝謝
                }
               ~Singleton( void )
                    {  assert( ms_Singleton );  ms_Singleton = 0;  }
                static T& getSingleton( void )
                    {  assert( ms_Singleton );  return ( *ms_Singleton );  }
                static T* getSingletonPtr( void )
                    {  return ( ms_Singleton );  }
            };
            使用如下
            class MyClass :public Singleton<MyClass>
            {
            public:
                void run();
            };
            *.cpp

            template MyClass* Singleton<MyClass>::ms_Singleton = NULL; ///注意,這里是Singleton構造函數.不是getSingleton方法
            //好像也可以用    template<typename T> T* Singleton<T>::ms_Singleton = NULL;
            //在使用它之前new一個對象
            new MyClass();
            MyClass::getSingleton().run();

            在CEGUI中為什么不設計如下呢??????????????????????????????
            emplate <class T> class  Singleton
            {
            protected:
                Singleton(){}
            public:
                
            static T& Instance()
                {
                    
            static T instance;
                    
            return instance;
                }
            };

            // Concrete singleton class, derived from Singleton<T>
            class ExampleSingleton: public Singleton<ExampleSingleton>
            {
                
            // so that Singleton<ExampleSingleton> can access the 
                
            // protected constructor
                friend class Singleton<ExampleSingleton>;

            protected:
                    ExampleSingleton(){}
            public:
                
            // This class's real functionalities
                void Write(){printf("Hello, World!");}
            };

            // use this singleton class
            ExampleSingleton::Instance().Write();

            Feedback

            # re: 08年04月18日  回復  更多評論   

            2008-04-18 18:25 by kun
            樓主啊`````我想加你的MSN,可以嗎?
            我們研究的進度是一樣的啊,剛好可以利用這個機會,加快我們兩個人的學習進度啊````

            # re: 08年04月18日  回復  更多評論   

            2008-04-18 18:29 by kun
            我的MSN : kun123456765@live.cn
            那個this是指 運行期的這個類的實例。

            posts - 94, comments - 138, trackbacks - 0, articles - 94

            Copyright © RichardHe

            久久男人AV资源网站| 久久中文字幕视频、最近更新| 久久无码一区二区三区少妇 | 亚洲精品NV久久久久久久久久| 久久亚洲中文字幕精品一区| 热久久最新网站获取| 久久综合亚洲欧美成人| 99久久人妻无码精品系列蜜桃 | 久久精品国产亚洲AV无码麻豆| 人人狠狠综合久久亚洲88| 日韩AV毛片精品久久久| 久久99精品久久只有精品| 久久91这里精品国产2020| 无码久久精品国产亚洲Av影片| 久久99中文字幕久久| 狠狠色婷婷久久综合频道日韩| 国产精品久久久天天影视| 亚洲国产精品成人久久蜜臀| 久久福利青草精品资源站| 一级a性色生活片久久无| 99久久国产亚洲高清观看2024 | 久久精品夜夜夜夜夜久久| 久久亚洲AV无码西西人体| 狠狠色丁香久久综合婷婷| 亚洲精品乱码久久久久久蜜桃不卡 | 丁香狠狠色婷婷久久综合| 中文精品99久久国产 | 欧美大战日韩91综合一区婷婷久久青草| 久久综合久久综合亚洲| 久久久人妻精品无码一区| 日本免费久久久久久久网站| 久久夜色精品国产噜噜亚洲AV| 综合久久精品色| 青春久久| 久久久国产99久久国产一| 欧美久久久久久午夜精品| 久久国产高清一区二区三区| 国产精品成人精品久久久| 久久av高潮av无码av喷吹| 久久99亚洲综合精品首页| 久久久久综合中文字幕|