• <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.
            狠狠综合久久综合中文88| 91精品国产综合久久四虎久久无码一级| 69久久夜色精品国产69| 久久99国产精品久久久| 狠狠精品久久久无码中文字幕| 久久国产成人午夜AV影院| 大香伊人久久精品一区二区| 久久99国产综合精品免费| 精品乱码久久久久久夜夜嗨| 久久精品国产亚洲AV不卡| 久久99久久成人免费播放| 亚洲国产精品无码久久久秋霞2 | 成人a毛片久久免费播放| 亚洲欧美成人久久综合中文网| 国内精品久久久久伊人av| 国产精品久久久久久久午夜片| 久久久这里有精品| 亚洲国产精品久久久久| 波多野结衣久久一区二区| 久久精品成人免费网站| 香蕉久久夜色精品升级完成| 精品久久久久中文字| 人妻无码中文久久久久专区| 7777精品久久久大香线蕉| 久久精品人妻中文系列| 精品久久久久久99人妻| 国产一区二区三区久久| 精品久久久久久久久午夜福利| 中文字幕无码久久精品青草| 久久久久婷婷| 伊人久久一区二区三区无码| 国产福利电影一区二区三区,免费久久久久久久精| 狠狠色丁香久久婷婷综合图片 | 久久久久人妻一区二区三区| 内射无码专区久久亚洲| 97精品伊人久久大香线蕉| 久久久久久久综合综合狠狠| 久久久久18| 亚洲欧洲中文日韩久久AV乱码| 久久综合亚洲色HEZYO国产| 国产精品免费久久久久电影网|