• <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精品国产一区二区三区 | 无码人妻久久一区二区三区免费| 伊人色综合久久天天人守人婷| 久久亚洲精品中文字幕| 青青国产成人久久91网| 久久人人爽人人爽人人片AV麻烦 | 久久精品国产亚洲av麻豆蜜芽| 久久久亚洲欧洲日产国码aⅴ| 久久久久国产一级毛片高清板| 久久精品免费一区二区| 国产精品激情综合久久| 久久天天躁狠狠躁夜夜网站| 久久九九免费高清视频| WWW婷婷AV久久久影片| 欧美日韩中文字幕久久久不卡| 久久成人国产精品| 伊人伊成久久人综合网777| 91精品国产91久久久久久| 久久午夜无码鲁丝片| 中文字幕亚洲综合久久菠萝蜜| 91性高湖久久久久| 久久99中文字幕久久| 欧美亚洲色综久久精品国产| 久久综合亚洲鲁鲁五月天| 久久99精品久久久久久齐齐| 99久久国产综合精品网成人影院| 国产精品久久波多野结衣| 日本欧美久久久久免费播放网 | 蜜臀久久99精品久久久久久| 亚洲国产精久久久久久久| 东京热TOKYO综合久久精品| 精品熟女少妇a∨免费久久| 色偷偷88888欧美精品久久久| 亚洲国产另类久久久精品黑人| 久久这里只精品99re66| 久久99热这里只有精品66| 77777亚洲午夜久久多喷| 国产毛片欧美毛片久久久| 亚洲中文字幕久久精品无码喷水 |