• <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>
            posts - 23,  comments - 94,  trackbacks - 0
             
            /************************************************************************/
            /* Copyright (c) 2009, Roc King
            All rights reserved.

            Redistribution and use in source and binary forms,
                with or without modification, are permitted
                provided that the following conditions are met:

            1. Redistributions of source code must retain the above copyright notice,
                this list of conditions and the following disclaimer.

            2. Redistributions in binary form must reproduce the above copyright notice,
                this list of conditions and the following disclaimer in the documentation
                and other materials provided with the distribution.

            3. Neither the name of the Tju nor the names of its contributors
                may be used to endorse or promote products derived from this software
                without specific prior written permission.

            THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
                AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
                INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
                INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
                (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
                LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                (INCLUDING NEGLIGENCE OR OTHERWISE)
                ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
                EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                                                     
            */
            /************************************************************************/


            /**
            這份代碼詳細介紹了使用SFINAE技術(shù)實現(xiàn)is_not_buildin_type的原理。
            按順序由上往下閱讀即可。
            */

            #include 
            <stdio.h>
            #include 
            <iostream>


            /** ------------------------------------------------------------------------ */
            #define DEFINITION(prefix)          \
            prefix none {};                     \
            prefix data { 
            int i; };             \
            prefix function { 
            void f(int ) {} };    \
            prefix both { 
            int i; double f() { return 0.0; } };

            namespace structures { DEFINITION(struct) }
            namespace s = structures;

            namespace classes { DEFINITION(class) }
            namespace c = classes;

            namespace unions { DEFINITION(union) }
            namespace u = unions;

            #undef DEFINITION

            /**
            上面對class、struct、union分別定義了:
            none        有數(shù)據(jù)成員,無成員函數(shù)
            data        有數(shù)據(jù)成員,沒成員函數(shù)
            function    無數(shù)據(jù)成員,有成員函數(shù)
            both        有數(shù)據(jù)成員,有成員函數(shù)
            */

            /** ------------------------------------------------------------------------ */

            void test_pointer_to_data_member() {

                
            // 一旦某個類型不是基本數(shù)據(jù)類型,就可以定義成員指針(數(shù)據(jù)成員指針,成員函數(shù)指針)。
                
            // 即使它沒有數(shù)據(jù)成員或者成員函數(shù)。

                
            // s::none 并沒有數(shù)據(jù)成員或者成員函數(shù)。
                int s::none::* p; //但是可以定義一個指向s的數(shù)據(jù)成員指針,只要類型不是void
                
            // void s::none::* p2; //error C2182: 'p2' : illegal use of type 'void'

                
            // 同時,在C++中,字面值0可以隱式轉(zhuǎn)換到任何指針類型。
                p = 0// ok
                double s::none::* p3 = 0// ok

                
            // 但是,如果某類型沒有對應(yīng)類型的數(shù)據(jù)成員,就不能用數(shù)據(jù)成員指針去指向它。
                int s::data::* p4 = 0;
                p4 
            = &s::data::i;  // ok
                double s::data::* p5 = 0;
                
            // p5 = &s::data::i;
                
            // error C2440: '=' : cannot convert from 'int structures::data::* ' to 'double structures::data::* '

                (
            void)p3; (void)p5;
            }

            // 這個是比較完整的測試
            void test_pointer_to_data_member_integrate();


            /** ------------------------------------------------------------------------ */

            void test_pointer_to_member_function() {
                
            // 同理,一旦某個類型不是基本類型,就可以定義指向該類型的成員函數(shù)的指針。
                
            // 并且字面值0可以隱式轉(zhuǎn)換到該指針。

                
            int (u::none::* p1)(void)  = 0;
                
            double (u::none::* p2)(double= 0;

                
            // 如果該類型確實有匹配的成員函數(shù),可以使用該成員函數(shù)給指針賦值。
                double (u::both::* p3 )(void= &u::both::f;
                
            void (u::function::* p4)(int= &u::function::f;

                
            // 否則不能賦值
                
            // double (u::both::* p5 )(void) = &u::function::f;
                
            //error C2440: 'initializing' : cannot convert from 'void (__thiscall unions::function::* )(int)' to 'double (__thiscall unions::both::* )(void)'
                
            // void (u::function::* p6)(int) = &u::both::f;
                
            //error C2440: 'initializing' : cannot convert from 'double (__thiscall unions::both::* )(void)' to 'void (__thiscall unions::function::* )(int)'

                (
            void)p1; (void)p2; (void)p3; (void)p4;
            }

            // 這個是比較完整的測試
            void test_pointer_to_member_function_integrate();

            /** ------------------------------------------------------------------------ */
            /**
            那么,測試一個類型是否是內(nèi)建類型的“一個”方法就是
            */

            namespace SFINAE {

                
            class true_type { char dummy; true_type(); };
                
            class false_type { char dummy[2]; false_type(); };
                
            // sizeof(true_type)!=sizeof(false_type)

                template
            <class C>
                true_type is_not_buildin_type_test(
            int C::* pointer_to_data_member);

                template
            <typename T>
                false_type is_not_buildin_type_test();

                
            void test_theory() {
                    
            using namespace std;

                    
            /* 在當前名字空間下, is_not_buildin_type_test是2個函數(shù)模板的名字:
                    template<class C>
                    true_type is_not_buildin_type_test(int C::* pointer_to_data_member);
                    (以下簡稱模板1)

                    template<typename T>
                    false_type is_not_buildin_type_test();
                    (以下簡稱模板2)

                    它們相互構(gòu)成重載。
                    
            */

                    cout
            <<sizeof( is_not_buildin_type_test<c::none>(0) )<<endl;
                    
            // 0 可以隱式轉(zhuǎn)化成 int c::none::* ,可以匹配模板1 (with C = c::none)

                    
            // 這里int是無關(guān)緊要的, 只要不是void就行
                    
            // 當然使用其他類型的數(shù)據(jù)成員指針 T C::* (T!=void)
                    
            // 或者成員函數(shù)指針進行測試 T (C::*)(paramter_list),也是可以的
                    
            // 只是int C::* 寫起來比較方便。

                    
            // 因為() 可以匹配任何類型的對象,
                    
            // 所以 0 也可以匹配模板2

                    
            // 又因為()處于重載選擇優(yōu)先級中的最底層,所以最終匹配模板1。
                    
            // 注意,此處模板2不能使用(int),或者(T*)因為它的優(yōu)先級高于(int C::*)


                    cout
            <<sizeof( is_not_buildin_type_test<double>(0) )<<endl;
                    
            // 0 不能隱式轉(zhuǎn)換成 int double::*,也就不能匹配模板1 ( with C=double )

                    
            // 但是還有一個“補救”的函數(shù)模板2,可以匹配任何類型的對象。
                    
            // 又因為SFINAE(Substitution failure is not an error)機制
                    
            // 所以對模板1的失敗的匹配并不報錯。
                }

                
            // 還有一些細節(jié)
                
            // 比如is_not_buildin_type_test并沒有實現(xiàn)。
                
            // 但是因為它同時也沒有被調(diào)用, 而僅僅是用sizeof測試它的返回值,所以不算錯誤。
                
            // 也防止了客戶無意調(diào)用這個函數(shù)。

                
            // 如何得知哪個is_not_buildin_type_test被重載選中?
                
            // 是通過返回值的大小不同來區(qū)分的。

                
            // 所以就需要true_type和false_type這2個東西。
                
            // 其實更合理的命名應(yīng)該是small_type和big_type。
                
            // 同時,它們聲明有私有的構(gòu)造函數(shù),并且不實現(xiàn),防止客戶使用這2個類。

                
            // 還因為is_not_buildin_type_test并沒有真正實現(xiàn)
                
            // 也就沒有真正返回true_type或者false_type
                
            // 所以沒有實現(xiàn)true_type和false_type的構(gòu)造函數(shù)也沒關(guān)系。

                
            // 一切都因為sizeof ……

                
            /** -------------------------------------------------------------------- */
                
            /**
                將這種方法再包裝一下
                (避免客戶去使用sizeof( xxx ) == sizeof( ture_type )等等)
                就得到
                
            */

                template
            <typename T>
                
            class is_not_buildin_type {
                    is_not_buildin_type();
                
            public:
                    
            enum { value =
                        
            sizeof(true_type)==sizeof( is_not_buildin_type_test<T>(0) ) };
                };
                
            // 或者將true_type,false_type,定義為它的內(nèi)嵌類型。
                
            // 同時將is_not_buildin_type_test定義為它的靜態(tài)成員函數(shù)。

                template
            <typename T>
                
            class is_not_buildin_type2 {
                    is_not_buildin_type2();

                    
            // 因為是內(nèi)嵌的private,客戶不能訪問
                    
            // 所以可以隨意一點
                    typedef char small_t;
                    
            struct big_t { small_t dummy[2]; };

                    template
            <typename U>
                    
            static big_t test(void (U::*)(shortfloat) );
                    
            // 只要是成員指針就ok,無論是數(shù)據(jù)成員指針還是成員函數(shù)指針。
                    
            // 也無論類型,簽名如何。

                    template
            <typename U>
                    
            static small_t test();
                    
            // 注意補救函數(shù)現(xiàn)在返回small_t

                
            public:
                    
            // 但這也是無關(guān)緊要的,因為small_t和big_t只是告之哪個重載被選中的方式。
                    
            // 只要這里處理好對應(yīng)就可以了。
                    enum { value= sizeof(big_t)==sizeof( test<T>(0) ) };
                };

                
            void test_wrapper() {
                    
            using namespace std;
                    cout
            <<is_not_buildin_type<c::data>::value<<endl;
                    cout
            <<is_not_buildin_type<u::both>::value<<endl;
                    cout
            <<is_not_buildin_type<float>::value<<endl;

                    cout
            <<is_not_buildin_type2<c::data>::value<<endl;
                    cout
            <<is_not_buildin_type2<u::both>::value<<endl;
                    cout
            <<is_not_buildin_type2<float>::value<<endl;
                }

                
            // 一個更完整的測試
                void test_wrapper_integrate();
            }

            /** ------------------------------------------------------------------------ */
            /**測試一個類型是否是內(nèi)建類型的另一個方法,需要更少的技巧。*/

            namespace partial_specialization {

                template
            <typename T>
                
            struct is_not_buildin_type { enum { value=true }; };
                
            // T不是一個內(nèi)建類型

                
            // 除非
                template<>
                
            struct is_not_buildin_type<int> { enum { value=false}; };
                
            // T是int
                template<>
                
            struct is_not_buildin_type<unsigned int> { enum { value=false}; };
                
            // T是unsigned int
                
            // .. more ..
            }

            int main()
            {
                
            using namespace std;
                test_pointer_to_data_member();
                test_pointer_to_data_member_integrate();
                test_pointer_to_member_function();
                test_pointer_to_member_function_integrate();

                cout
            <<endl;
                SFINAE::test_theory();
                cout
            <<endl;
                SFINAE::test_wrapper();
                cout
            <<endl;
                SFINAE::test_wrapper_integrate();
            }



            void test_pointer_to_data_member_integrate() {
                
            // to do
            }
            void test_pointer_to_member_function_integrate() {
                
            // to do
            }

            namespace SFINAE {
                
            void test_wrapper_integrate() {
                    
            // to do
                }
            }

            這個代碼已經(jīng)能很完美的解釋了~
            今天看了C++ Templates 的15章.. 收獲頗多.. 以前的很多疑惑都比較開朗了~

            posted @ 2009-03-16 23:32 Charlie 侯杰 閱讀(2659) | 評論 (3)編輯 收藏
             1 #include <iostream>
             2 #include <boost/shared_ptr.hpp>
             3 #include <boost/enable_shared_from_this.hpp>
             4 
             5 using namespace std;
             6 
             7 class A : public boost::enable_shared_from_this<A>
             8 {
             9 public:
            10     boost::shared_ptr<A> child_;
            11     boost::shared_ptr<A> parent_;
            12 
            13     void add(boost::shared_ptr<A> child)
            14     {
            15         child_ = child;
            16         child_->set(shared_from_this());
            17     }
            18 
            19     void set(boost::shared_ptr<A> parent)
            20     {
            21         parent_ = parent;
            22     }
            23 };
            24 
            25 int main()
            26 {
            27     boost::shared_ptr<A> p1(new A);
            28     boost::shared_ptr<A> p2(new A);
            29 
            30     p1->add(p2);
            31 
            32     cout<<p1<<endl;
            33     cout<<p2<<endl;
            34     cout<<p1->child_<<endl;
            35     cout<<p2->parent_<<endl;
            36     cout<<p1.use_count()<<endl;
            37     cout<<p2.use_count()<<endl;
            38 
            39     return 0;
            40 }

            有了shared_from_this.. 我淚流滿面
            之前不知道這個的時候..用了很愚蠢的做法

            void add(shared_ptr<A> child)
                child_ = child;
                child_->set(shared_ptr<A>(this));
            }
            結(jié)果錯誤連連~ 然后放棄使用shared_ptr... 用raw_ptr...

            順便推薦這本書
            beyond_stl_cn.chm

            放到了我的SVN上.. 一本很好的介紹Boost如何使用的書..

            http://code.google.com/p/charlib/source/browse/trunk/Boost%20Book/Beyond_STL_cn.rar

            進入頁面后點右下的 view raw file 就可以下載了

            以上是早上寫的.. 寫好后很高興的發(fā)布了.. 但是后來發(fā)現(xiàn)上面這段程序非常的白癡
            最關(guān)鍵的就在于,其實這上面的兩個shared_ptr已經(jīng)循環(huán)引用了.. 再也沒有辦法自動解開
            資源也就套死在了原地.. Oh My God... 居然愚蠢到這種地步..

            然后才發(fā)現(xiàn).. weak_ptr 一點都不weak.. 這里就需要用weak_ptr來處理!

            換成下面這個...
            #include <iostream>
            #include 
            <boost/shared_ptr.hpp>
            #include 
            <boost/weak_ptr.hpp>
            #include 
            <boost/enable_shared_from_this.hpp>

            using namespace std;

            class A : public boost::enable_shared_from_this<A>
            {
            public:
                A(
            const int id) : id_(id) { cout<<id_<<" Constructed!"<<endl; }
                
            ~A() { cout<<id_<<" Destructed!"<<endl; }

                
            int id_;
                boost::shared_ptr
            <A> child_;
                boost::weak_ptr
            <A> parent_;

                
            void add(boost::shared_ptr<A> child)
                {
                    child_ 
            = child;
                    child_
            ->set(shared_from_this());
                }

                
            void set(boost::shared_ptr<A> parent)
                {
                    parent_ 
            = parent;
                }

                boost::shared_ptr
            <A> get_parent()
                {
                    
            return parent_.lock();
                }
            };

            int main()
            {
                boost::shared_ptr
            <A> p1(new A(1));
                boost::shared_ptr
            <A> p2(new A(2));

                p1
            ->add(p2);

                
            return 0;
            }

            通過這個測試..
            輸出的結(jié)果是
            1 Construct
            2 Construct
            1 Destruct
            2 Destruct

            這樣的輸出并不奇怪. 因為 weak_ptr 是 shared_ptr 的觀察者,將 shared_ptr 傳給 weak_ptr 不會增加 shared_ptr的引用計數(shù). 所以這里的操作, p2 的引用計數(shù)是2, p1 的引用計數(shù)是1, 所以p1是unique的,p1先析構(gòu),p2的引用計數(shù)-1,然后析構(gòu).

            不過這里資源的析構(gòu)順序可能不是我們關(guān)心的范圍,我這里認為把資源丟給智能指針這類物件管理后,主要是為了資源不泄漏,資源的析構(gòu)順序如果在關(guān)心的范圍,也就該自己管理該資源了.

            自己犯的一個低級錯誤,趕忙把帖子存草稿了. 現(xiàn)在弄清楚怎么處理后,才敢發(fā)上來,呵呵~ ^ ^

            posted @ 2009-03-12 19:20 Charlie 侯杰 閱讀(8950) | 評論 (4)編輯 收藏
            為了達到泛型和范維.. 用模板定義了維數(shù)和數(shù)據(jù)類型
            Vector使用std::valarray
            Matrix使用Vector

            Matrix實際上還沒有完成.. 留下了比較難的 求逆陣的運算..
            晚上在寫transpose的時候也發(fā)現(xiàn)..
            Matrix<m,n> 要轉(zhuǎn)置就會變成 Matrix<n,m>
            由于模板實現(xiàn)的問題,好像不能讓自身轉(zhuǎn)置...改變自身的維度

            具體見:

            http://code.google.com/p/charlib/source/browse/trunk/Charlib/includes/Vector.hpp

            http://code.google.com/p/charlib/source/browse/trunk/Charlib/includes/Matrix.hpp

            不過很少有這么長篇的使用過模板寫東西.. 還是算一次比較不錯的練習~

            posted @ 2009-03-10 00:41 Charlie 侯杰 閱讀(1127) | 評論 (7)編輯 收藏
            嗯.. SVN上上傳PlayerState.cbp
            該工程實現(xiàn) State 設(shè)計模式

            具體如下...

             1 //forward decl
             2 class PlayerState;
             3 
             4 class Player
             5 {
             6 public:
             7     Player(PlayerState* initState);
             8 
             9     void walk();
            10     void stand();
            11     void jump();
            12 
            13     void setState(PlayerState* state);
            14 protected:
            15     PlayerState* mState;
            16 
            17     //decl uncopyable
            18     Player(const Player& player);
            19     Player& operator=(const Player& rhs);
            20 };
            21 

            玩家的行為轉(zhuǎn)由狀態(tài)對象處理

            //forward decl
            class Player;

            class PlayerState
            {
            public:
                
            virtual void walk(Player* player) = 0;
                
            virtual void stand(Player* player) = 0;
                
            virtual void jump(Player* player) = 0;
            };

            class Walking : public PlayerState
            {
            public:
                
            void walk(Player* player);
                
            void stand(Player* player);
                
            void jump(Player* player);

                
            static Walking* getInstancePtr();
            protected:
                
            //singleton
                Walking();

                
            static Walking* mInstance;
            };

            class Standing : public PlayerState
            {
            public:
                
            void walk(Player* player);
                
            void stand(Player* player);
                
            void jump(Player* player);

                
            static Standing* getInstancePtr();
            protected:
                Standing();

                
            static Standing* mInstance;
            };

            class Jumping : public PlayerState
            {
            public:
                
            void walk(Player* player);
                
            void stand(Player* player);
                
            void jump(Player* player);

                
            static Jumping* getInstancePtr();
            protected:
                Jumping();

                
            static Jumping* mInstance;
            };

            相對比較簡單... 可以當一個非常無聊的文字MUD來玩..

            具體見
            http://code.google.com/p/charlib/source/browse/trunk/
            下的 PlayerState 文件夾

            posted @ 2009-03-02 18:05 Charlie 侯杰 閱讀(1360) | 評論 (2)編輯 收藏
            前兩天某C++群正好在討論C++中int類型的長度
            對于支持C99標準的編譯器來說,可以#include <cstdint>
            來使用 int32_t, 但是目前不少的編譯器都做不到這點
            所以,自己寫了個IntType.hpp

             1 #ifndef INTTYPE_HPP_
             2 #define INTTYPE_HPP_
             3 
             4 #include "Platform.hpp"
             5 
             6 namespace Charlie
             7 {
             8 
             9 typedef long long int64_t;
            10 typedef int       int32_t;
            11 typedef short     int16_t;
            12 typedef char      int8_t;
            13 
            14 typedef unsigned long long uint64_t;
            15 typedef unsigned int       uint32_t;
            16 typedef unsigned short     uint16_t;
            17 typedef unsigned char      uint8_t;
            18 
            19 }
            20 
            21 #endif // INTTYPE_HPP_
            22 

            然后今天大部分時間都消耗在了Timer的跨平臺處理上

            這里采用了Bridge Design Pattern
            即pImpl方法,實現(xiàn)了Linux 和 Windows 兩個平臺相關(guān)的高精度計時器
            接口設(shè)計得很簡單,只能得到計時器定義以來經(jīng)過的時間(單位是毫秒 //雖然精度都高于毫秒)

            具體請見一下幾個文件了

            http://code.google.com/p/charlib/source/browse/trunk/Charlib/includes/Timer.hpp
            http://code.google.com/p/charlib/source/browse/trunk/Charlib/includes/TimerImpl.hpp
            http://code.google.com/p/charlib/source/browse/trunk/Charlib/includes/LinuxTimerImpl.hpp
            http://code.google.com/p/charlib/source/browse/trunk/Charlib/includes/Win32TimerImpl.hpp
            以及對應(yīng)的srcs下的.cpp文件

            基本上是這樣

            Timer {
            protected:
                TimerImpl* pImpl;
            }

            class LinuxTimerImpl : public TimerImpl {}
            class Win32TimerImpl : public TimerImpl {}

            還定義了一個用于多平臺多編譯器的平臺辨識頭文件 - Platform.hpp

            目前SVN上也有VC 05的工程 和 Code::Blocks 的工程文件
            代碼在Windows下 MINGW 和 MSVC 8 兩個編譯器上編譯通過
            在Ubuntu下使用Code::Blocks + GCC 編譯器上通過

            // fibonacci數(shù)列的模板元編程版本因為在Ubuntu下GCC編譯未通過,所以注釋掉了,但是在MSVC 8和Code::Blocks的MINGW下編譯通過

            SVN地址: http://charlib.googlecode.com/svn/trunk/

            其他雜項:
                HugeInt added 預(yù)計在有空的時候會完成,用于高精度整形的運算 = =~!

            posted @ 2009-03-01 21:15 Charlie 侯杰 閱讀(2012) | 評論 (4)編輯 收藏
            在Google上建了一個自己的SVN
            想用來把自己的習作存一存

            這學期開了算法課,可能會有很多C++實作的算法練習
            還有一些設(shè)計模式的練習
            可能還有一些雜項

            還有一個目標就是能寫出平臺無關(guān)的代碼
            還在努力中……

            目前使用 Visual C++ 2008 Express 版本的工程
            以后可能會使用Code::Blocks來做

            估計除了DirectX的練習部分,其他都會平臺無關(guān)

            地址:
                http://code.google.com/p/charlib/

            Charlib 是 Charlie + lib 的意思,不是 字符 - 庫 ~

            昨天在研究斐波那契數(shù)列,還需要完善
            目前寫了比較基礎(chǔ)的

            NonCopyable
                用于規(guī)定無法復(fù)制的類
            Timer
                *依賴WindowsAPI的高精度計時器,精度超過ms

            Fibonacci數(shù)列
                模板元編程 版本
                遞歸求解版本
                遞推求解版本

            posted @ 2009-03-01 10:29 Charlie 侯杰 閱讀(230) | 評論 (0)編輯 收藏
            初見這個內(nèi)容是在Effective C++上,在構(gòu)造函數(shù)和析構(gòu)函數(shù)中調(diào)用虛函數(shù)是非常不好的行為一個簡單的例子?class?Base{public:????Base()????{????????cout
            文章來源:http://blog.csdn.net/huntrose/archive/2008/11/06/3230766.aspx
            posted @ 2009-03-01 10:16 Charlie 侯杰 閱讀(173) | 評論 (0)編輯 收藏
            C++
            文章來源:http://blog.csdn.net/huntrose/archive/2008/11/15/3305351.aspx
            posted @ 2009-03-01 10:16 Charlie 侯杰 閱讀(225) | 評論 (0)編輯 收藏
            #include? using?namespace?std;class?Door{public:????virtual?void?open()?{????????cout
            文章來源:http://blog.csdn.net/huntrose/archive/2008/11/16/3312184.aspx
            posted @ 2009-03-01 10:16 Charlie 侯杰 閱讀(230) | 評論 (0)編輯 收藏
            指針是C++中不得不談的一個話題,或許我還不是很能熟練的掌握指針以及我所要討論的引用計數(shù)型指針的全部,但是還是有那么些迫不及待想要表達一下。指針 pointer 是資源泄漏 resource leak 的根源(當然可能還有其他一些什么東西,在我的映像中異常仿佛也會造成資源泄漏)最簡單的一個資源泄漏的例子就是new和delete這樣的動態(tài)內(nèi)存分配算子沒有正確使用造成的:struct A {??? A() ?{ printf("A Constructor!"); }??? ~A() { printf("A Destructor!"); }};void area(){??? A *p = new A();}執(zhí)行完 area() 后,自然是只有A構(gòu)造的消息,而A的析構(gòu)卻不見影蹤。這里我們在離開了area作用域后,我們就無法對p所指向之資源進行操作,A的實例就會被懸掛在內(nèi)存的某處得不到清理。一個形象
            文章來源:http://blog.csdn.net/huntrose/archive/2008/11/18/3326388.aspx
            posted @ 2009-03-01 10:16 Charlie 侯杰 閱讀(124) | 評論 (0)編輯 收藏
            僅列出標題
            共3頁: 1 2 3 
            by Charlie
            日韩亚洲欧美久久久www综合网| 午夜天堂精品久久久久| 99久久夜色精品国产网站| 久久综合综合久久97色| 久久精品免费网站网| 无码8090精品久久一区 | 久久一区二区三区免费| 97久久国产露脸精品国产| 国内精品久久久久久野外| 青青热久久国产久精品| 97热久久免费频精品99| 欧美一级久久久久久久大片| 久久婷婷五月综合色高清| 久久无码人妻精品一区二区三区| 久久人人爽人人爽人人爽| 国产成人香蕉久久久久| 久久久国产乱子伦精品作者| 中文字幕久久亚洲一区| 国产91久久综合| 国产精品久久永久免费| 狠狠色狠狠色综合久久 | 亚洲成色www久久网站夜月 | 亚洲国产欧洲综合997久久| 欧美色综合久久久久久| 99久久夜色精品国产网站| 久久一日本道色综合久久| 日韩精品无码久久一区二区三| 久久午夜电影网| 国内精品久久久久影院优| 97久久国产露脸精品国产| 久久久无码精品亚洲日韩蜜臀浪潮 | 久久综合亚洲色HEZYO社区| 亚洲精品综合久久| 欧美亚洲国产精品久久久久| 亚洲国产成人精品女人久久久| 久久一本综合| 亚洲国产成人精品女人久久久 | 亚洲乱码精品久久久久..| 久久只有这里有精品4| 热99RE久久精品这里都是精品免费| 欧美久久一区二区三区|