• <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.
            久久精品国产网红主播| 久久人做人爽一区二区三区 | 伊人热人久久中文字幕| 亚洲国产成人久久精品影视| 久久久久无码精品国产app| 久久这里都是精品| 久久影院综合精品| 国产免费久久久久久无码| 久久经典免费视频| 人人狠狠综合久久亚洲88| 国产精品久久久久久久久软件| 麻豆一区二区99久久久久| 久久AAAA片一区二区| 久久久久亚洲AV片无码下载蜜桃| 久久精品视屏| 国产成人久久激情91| 天天躁日日躁狠狠久久| 久久久久久久亚洲精品| 久久福利青草精品资源站| 日产精品久久久久久久| 一级女性全黄久久生活片免费| 狠狠色丁香婷婷综合久久来 | 久久精品成人免费国产片小草| 蜜臀av性久久久久蜜臀aⅴ| 一本久久a久久精品综合香蕉| 久久免费小视频| 成人妇女免费播放久久久| 狠狠色丁香久久婷婷综合_中 | 91久久精品无码一区二区毛片| 99久久免费国产精品特黄| 久久综合五月丁香久久激情| 99久久精品九九亚洲精品| 91精品观看91久久久久久| 久久亚洲国产午夜精品理论片 | 亚洲人成网亚洲欧洲无码久久| 久久夜色撩人精品国产| 久久婷婷人人澡人人| 久久久久久亚洲精品影院| 欧美亚洲国产精品久久高清| 中文字幕日本人妻久久久免费| 久久99久国产麻精品66|