• <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 閱讀(192) 評論(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

            久久ww精品w免费人成| 精品久久久久国产免费 | 久久伊人精品青青草原日本| 国产精品久久久久久一区二区三区| 伊人色综合久久天天网 | 国产精品久久久久久久人人看| 日本久久久精品中文字幕| 久久91综合国产91久久精品| 久久棈精品久久久久久噜噜| 97久久精品无码一区二区 | 久久精品人人做人人爽电影蜜月 | 国产成人精品白浆久久69| AV无码久久久久不卡蜜桃| 精品熟女少妇a∨免费久久| 国产成人无码久久久精品一| 久久精品视频网| 久久九色综合九色99伊人| 合区精品久久久中文字幕一区| 久久伊人五月天论坛| 久久天天躁夜夜躁狠狠| 99久久人妻无码精品系列蜜桃| 中文字幕成人精品久久不卡| 久久天天躁狠狠躁夜夜2020老熟妇| 人妻无码αv中文字幕久久琪琪布| 久久久久久久久久久久中文字幕| 久久国产一区二区| 人妻无码精品久久亚瑟影视| 色偷偷偷久久伊人大杳蕉| 久久精品国产99国产精偷 | 77777亚洲午夜久久多喷| 99re这里只有精品热久久| 久久伊人五月天论坛| 亚洲国产另类久久久精品| 久久久久久久久久免免费精品| 伊人久久大香线蕉AV色婷婷色| 久久美女网站免费| 精品久久久无码21p发布| 欧美一区二区精品久久| 丁香色欲久久久久久综合网| 国产成人精品久久亚洲高清不卡| 亚洲成色WWW久久网站|