• <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 - 9, comments - 0, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理
            base class constructors execute before derived class constructors, derived class data members have not been initialized when base class constructors run. If virtual functions called during base class construction went down to derived classes, the derived class functions would almost certainly refer to local data members, but those data members would not yet have been initialized.Calling down to parts of an object that have not yet been initialized is inherently dangerous, so C++ gives you no way to do it.

            #include <iostream>
            #include <string>
            #include <cstdlib>
            void print(std::string str){std::cout << str<< std::endl;}
            class Transaction {
                public:
                    Transaction()
                    {
                        print("Transaction Constructor");
                        logTransaction();
                    }
                    virtual void logTransaction() const // =0;
                    {
                        print("Transaction Log");
                    }
            };
            class BuyTransaction: public Transaction
            {
                public:
                    BuyTransaction(){   print("BuyTransaction Constructor");}
                    virtual void logTransaction() const
                    {
                        print("BuyTransaction Log");
                    }
            };
            int main()
            {
                BuyTransaction dbc;
                //dbc.logTransaction();
            }
            pure virtual functions cannot link.
            [shangtang@BTSOM-1 study]$ g++ TestT.cpp
            TestT.cpp: In constructor 'Transaction::Transaction()':
            TestT.cpp:14: warning: abstract virtual 'virtual void Transaction::logTransaction() const' called from constructor
            /tmp/ccXFzaHv.o: In function `Transaction::Transaction()':
            TestT.cpp:(.text._ZN11TransactionC2Ev[Transaction::Transaction()]+0x7f): undefined reference to `Transaction::logTransaction() const'
            collect2: ld returned 1 exit status
            virtual function can compile, run, but with surprise result
            [shangtang@BTSOM-1 study]$ ./a.out
            Transaction Constructor
            Transaction Log
            BuyTransaction Constructor

            The only way to avoid this problem is to make sure that none of your constructors or destructors call virtual functions on the object being created or destroyed and that all the functions they call obey the same constraint.
            97久久超碰国产精品旧版| 久久免费视频网站| 久久亚洲熟女cc98cm| 精品久久久久久中文字幕大豆网| 99精品国产综合久久久久五月天 | 久久99精品国产麻豆| 久久香蕉国产线看观看乱码| 久久婷婷人人澡人人| 欧美一区二区三区久久综| 久久久久综合国产欧美一区二区 | 精品综合久久久久久88小说| 日韩人妻无码一区二区三区久久99| 久久超碰97人人做人人爱| 久久综合成人网| 成人免费网站久久久| 久久人妻AV中文字幕| 久久亚洲高清综合| 久久综合狠狠综合久久激情 | 久久久久成人精品无码中文字幕 | 久久综合久久自在自线精品自| 国产精品免费看久久久香蕉| 久久久婷婷五月亚洲97号色| 中文字幕精品无码久久久久久3D日动漫 | 亚洲中文久久精品无码| 亚洲成av人片不卡无码久久| 99久久亚洲综合精品成人| 久久综合给久久狠狠97色| 久久人与动人物a级毛片| 亚洲国产精品综合久久一线| 久久精品无码一区二区三区免费| 久久天堂电影网| 伊人久久大香线蕉影院95| 国产精品无码久久久久久| 精品久久久久久无码专区| 精品乱码久久久久久久| 99久久免费国产精精品| 国产综合久久久久| 91精品国产高清久久久久久国产嫩草 | 国产亚洲精品久久久久秋霞 | 久久精品国产亚洲综合色| 国产精品久久网|