• <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++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
            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.
            国产精品嫩草影院久久| 久久一区二区免费播放| 精品久久久久久亚洲精品| 国产精品久久久天天影视| 久久AV高清无码| 人人狠狠综合88综合久久| 久久精品一本到99热免费| 国产99久久精品一区二区| 亚洲综合久久久| 久久久久久a亚洲欧洲aⅴ| 久久久综合香蕉尹人综合网| 久久天天躁狠狠躁夜夜96流白浆| 国产精品成人无码久久久久久| 久久99热这里只频精品6| 欧美综合天天夜夜久久| 香蕉久久av一区二区三区| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 久久亚洲国产精品123区| 无码日韩人妻精品久久蜜桃 | 久久伊人中文无码| 久久久91精品国产一区二区三区| 欧美一区二区久久精品| 久久综合久久鬼色| 国产亚州精品女人久久久久久| 日韩人妻无码精品久久久不卡| 伊人久久成人成综合网222| 99久久人人爽亚洲精品美女| 蜜臀久久99精品久久久久久小说| 久久亚洲熟女cc98cm| 亚洲国产成人久久综合一区77| 国内精品伊人久久久久影院对白| 久久福利青草精品资源站免费| 性欧美大战久久久久久久久| 久久伊人五月丁香狠狠色| 久久综合偷偷噜噜噜色| 亚洲国产精品成人AV无码久久综合影院 | 国产精品青草久久久久婷婷| 一本一本久久aa综合精品| 中文字幕乱码人妻无码久久| 欧美伊人久久大香线蕉综合| 欧美精品九九99久久在观看|