• <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.
            久久av高潮av无码av喷吹| 国产99久久九九精品无码| 国内精品久久久久久久涩爱| 一级做a爰片久久毛片人呢| 亚洲欧美日韩精品久久| 亚洲国产日韩综合久久精品| 伊人久久精品无码av一区| 国产成人精品久久亚洲| 一级a性色生活片久久无少妇一级婬片免费放 | 欧美精品乱码99久久蜜桃| 亚洲国产美女精品久久久久∴| 久久777国产线看观看精品| 亚洲&#228;v永久无码精品天堂久久| 久久久久久综合网天天| 色综合久久最新中文字幕| 一本久久a久久精品综合香蕉 | 亚洲精品乱码久久久久66| 91精品观看91久久久久久| AV无码久久久久不卡蜜桃| 久久人人爽人人爽人人片AV东京热| 久久久久久国产精品无码超碰| 久久久不卡国产精品一区二区| 97久久超碰成人精品网站| 亚洲日本va中文字幕久久| 久久亚洲国产成人影院网站| 欧美久久综合性欧美| 久久精品人人做人人妻人人玩 | 久久国产免费直播| 开心久久婷婷综合中文字幕| 国产伊人久久| 99久久综合国产精品二区| 久久亚洲日韩精品一区二区三区| 亚洲精品久久久www| 久久综合伊人77777| 日韩亚洲国产综合久久久| 久久精品中文字幕有码| 久久伊人精品青青草原日本| 精品国产91久久久久久久a| 狠狠精品干练久久久无码中文字幕| 99久久www免费人成精品 | 一级女性全黄久久生活片免费 |