• <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.
            久久久久国产一级毛片高清板| 亚洲国产精品综合久久一线| 91久久国产视频| 久久久久国产成人精品亚洲午夜| 久久受www免费人成_看片中文| 久久久久亚洲av无码专区导航| 精品熟女少妇aⅴ免费久久| 久久久噜噜噜久久中文字幕色伊伊 | a级毛片无码兔费真人久久| 综合久久精品色| 久久久久国产精品| 久久久久免费精品国产| 精品久久久久国产免费| 精品久久久久久| 亚洲国产精品无码久久久秋霞2| 国产精品无码久久综合网| 久久99国内精品自在现线| 2021国产精品久久精品| 很黄很污的网站久久mimi色| 国产成人久久精品一区二区三区| 久久午夜无码鲁丝片秋霞 | 色婷婷综合久久久中文字幕| 久久无码一区二区三区少妇| 国产精品九九久久免费视频| 91久久精品91久久性色| 久久国产欧美日韩精品| 无码超乳爆乳中文字幕久久| 亚洲精品无码久久久久去q | 99国产精品久久| av无码久久久久久不卡网站| 久久亚洲日韩精品一区二区三区| 狠狠色噜噜色狠狠狠综合久久| 精品久久久久久无码不卡| 久久乐国产综合亚洲精品| 性做久久久久久久久| 日韩人妻无码一区二区三区久久99 | 嫩草影院久久国产精品| 青青青国产精品国产精品久久久久 | 久久久久免费视频| 三级三级久久三级久久| 亚洲AV日韩精品久久久久久|