• <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.
            国产香蕉97碰碰久久人人| 久久―日本道色综合久久| 中文成人久久久久影院免费观看| 欧美久久久久久精选9999| 91久久成人免费| 亚洲伊人久久大香线蕉综合图片| 久久久久成人精品无码中文字幕| 天天影视色香欲综合久久| 热久久视久久精品18| 久久无码一区二区三区少妇 | 麻豆精品久久精品色综合| 久久777国产线看观看精品| 影音先锋女人AV鲁色资源网久久| 无码AV波多野结衣久久| 香蕉久久久久久狠狠色| 狠狠色丁香久久婷婷综| 大香伊人久久精品一区二区| 久久中文字幕精品| 色综合合久久天天综合绕视看| 狠狠色丁香久久婷婷综合| 精品国产一区二区三区久久蜜臀| 99精品国产99久久久久久97 | 99久久综合狠狠综合久久止| 久久精品天天中文字幕人妻| 日韩精品无码久久一区二区三| 国产日产久久高清欧美一区| 亚洲国产欧洲综合997久久| 一本一道久久a久久精品综合 | 精品免费久久久久国产一区 | 久久无码人妻精品一区二区三区| 996久久国产精品线观看| 无码国产69精品久久久久网站| 亚洲&#228;v永久无码精品天堂久久 | 欧美日韩成人精品久久久免费看| 国产成人精品久久亚洲| 日韩欧美亚洲国产精品字幕久久久| 久久精品国产精品国产精品污| 91视频国产91久久久| 国产91久久精品一区二区| 久久国产色AV免费观看| 国产精品一区二区久久|