• <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.
            一本色道久久综合狠狠躁| 国产精品欧美久久久天天影视 | 久久电影网2021| 久久精品成人欧美大片 | 久久人人爽人人爽人人AV东京热| 久久久久国色AV免费看图片| 精品久久久久久久久中文字幕| 亚洲国产精品无码久久久蜜芽 | 久久久久亚洲AV无码观看| 久久久久99精品成人片牛牛影视| 国产精品久久久久天天影视| 久久精品国产91久久麻豆自制| 9久久9久久精品| 天天久久狠狠色综合| 国产综合成人久久大片91| 精品无码久久久久久国产| 国产精品成人99久久久久| 99久久伊人精品综合观看| 精品人妻伦九区久久AAA片69| 久久久久一级精品亚洲国产成人综合AV区| 国产成人精品久久综合| 亚洲国产天堂久久久久久| 久久无码专区国产精品发布| 日韩精品久久久久久免费| 久久久久久无码Av成人影院| 久久九九精品99国产精品| 91久久精品国产成人久久| 久久亚洲精品无码播放| 无码伊人66久久大杳蕉网站谷歌| 97久久香蕉国产线看观看| 亚洲精品NV久久久久久久久久| 人妻无码精品久久亚瑟影视 | 午夜精品久久久久| 亚洲精品蜜桃久久久久久| 99久久国产综合精品网成人影院 | 国内精品久久九九国产精品| 久久久久亚洲爆乳少妇无 | 国产精品视频久久久| 亚洲色欲久久久久综合网| 久久精品视频免费| 2021国产精品久久精品|