• <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.
            国产精品久久久久a影院| 99久久国语露脸精品国产| 久久无码高潮喷水| 日韩精品久久久肉伦网站| 国产成人精品久久一区二区三区av| 青青草国产97免久久费观看| 久久久久久久久久久久中文字幕| 国产精品99久久久久久猫咪| 伊人久久综合成人网| 欧美与黑人午夜性猛交久久久 | 久久国产成人精品麻豆| 伊人热热久久原色播放www| 好属妞这里只有精品久久| 无码人妻少妇久久中文字幕| 国产 亚洲 欧美 另类 久久| 久久综合亚洲欧美成人| 久久人做人爽一区二区三区| 国产成人精品久久一区二区三区av| 欧美精品久久久久久久自慰| 亚洲国产成人久久一区WWW| 国产亚洲美女精品久久久久狼| 久久伊人五月丁香狠狠色| 欧美国产成人久久精品| 国产精品日韩深夜福利久久| 久久久久久综合一区中文字幕| 伊人久久综合精品无码AV专区| 久久强奷乱码老熟女网站| 中文字幕无码久久久| 欧美亚洲国产精品久久| 久久久久久国产a免费观看黄色大片 | 99久久久精品免费观看国产| 午夜精品久久久内射近拍高清| 久久久噜噜噜久久熟女AA片| 亚洲女久久久噜噜噜熟女| 日本WV一本一道久久香蕉| 一级a性色生活片久久无| 精品国产日韩久久亚洲| 99久久99久久精品国产片果冻 | a级成人毛片久久| AAA级久久久精品无码区| 日本精品久久久久中文字幕8 |