• <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.
            一本久久免费视频| 色综合久久久久无码专区| 久久中文娱乐网| 久久久WWW成人免费毛片| 欧美精品九九99久久在观看| 亚洲中文精品久久久久久不卡| 嫩草伊人久久精品少妇AV| 久久精品国内一区二区三区| 青青青国产精品国产精品久久久久| 国产精品无码久久久久| 亚洲精品乱码久久久久久不卡| 99久久精品国产麻豆| 久久久久久久免费视频| 青青青国产成人久久111网站| 久久99这里只有精品国产| 国产欧美久久久精品| 久久国产欧美日韩精品| 精品久久久久久无码免费| 久久婷婷五月综合国产尤物app | 久久人人爽人人爽人人片AV东京热 | 国产毛片欧美毛片久久久| 国产精品成人无码久久久久久 | 7777久久亚洲中文字幕| 亚洲а∨天堂久久精品9966| 伊人久久精品线影院| 久久久久亚洲AV无码麻豆| 久久亚洲中文字幕精品一区| 久久久久这里只有精品| 久久婷婷久久一区二区三区| 久久久噜噜噜久久中文福利| 久久综合久久美利坚合众国| 久久伊人中文无码| 亚洲Av无码国产情品久久| 久久久久国产精品三级网| 精品无码久久久久久国产| 日韩精品久久久久久| 国产精品国色综合久久| jizzjizz国产精品久久| 久久久久综合网久久| 狠狠狠色丁香婷婷综合久久俺| 久久66热人妻偷产精品9|