• <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.
            欧美午夜A∨大片久久 | 国产精品欧美久久久久天天影视| 久久精品夜夜夜夜夜久久| 久久精品国产精品亚洲精品| 伊人色综合久久天天| 久久伊人五月丁香狠狠色| AV无码久久久久不卡蜜桃| 久久国产精品免费| 97久久国产综合精品女不卡| 91精品国产高清久久久久久国产嫩草 | 久久久久黑人强伦姧人妻| 久久亚洲日韩看片无码| 久久99中文字幕久久| 亚洲欧美久久久久9999| 久久综合丁香激情久久| 国产成人精品综合久久久久| 精品无码久久久久久国产| 欧美黑人又粗又大久久久| 性做久久久久久久久久久| 国产精品欧美久久久天天影视| 精品久久久一二三区| 国产成人精品综合久久久| 久久夜色精品国产亚洲| 久久99国内精品自在现线| 久久久久国产精品嫩草影院| 久久久久亚洲av成人无码电影| 久久精品国产免费一区| 2021久久国自产拍精品| 一本色道久久综合亚洲精品| 色婷婷狠狠久久综合五月| 精品久久久无码中文字幕| 97超级碰碰碰碰久久久久| 99久久精品影院老鸭窝| 久久国产精品无码一区二区三区 | 麻豆精品久久久久久久99蜜桃| 欧美激情精品久久久久久久| 国产农村妇女毛片精品久久| 国内精品伊人久久久久网站| 精品国产乱码久久久久久浪潮| 国产精品成人99久久久久 | 91精品国产91久久久久久|