亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: C++的虛表到底是怎么玩的?求指教 [打印本頁]

作者: mci2004    時間: 2013-11-26 09:35
標題: C++的虛表到底是怎么玩的?求指教
  1. /*
  2. * =====================================================================================
  3. *
  4. *       filename:  test.cpp
  5. *
  6. *    description:  
  7. *
  8. *        version:  1.0
  9. *        created:  11/25/2013 08:17:32 pm
  10. *       revision:  none
  11. *       compiler:  gcc
  12. *
  13. *         author:  alan wang (), alan.3976@gmail.com
  14. *   organization:  
  15. *
  16. * =====================================================================================
  17. */
  18. #include <iostream>
  19. using namespace std;

  20. class ca {

  21.     public:
  22.         virtual ~ca() {
  23.             cout << "deconstructor in ca !" << endl;
  24.         }
  25. };

  26. class cb {

  27.     public:
  28.        virtual ~cb() {
  29.             cout << "deconstructor in cb !" << endl;
  30.        }
  31. };

  32. class cc : public ca, public cb {
  33.    
  34.     public:
  35.         virtual ~cc() {
  36.             cout << "deconstructor in cc !" << endl;
  37.         }
  38. };


  39. class cd: public cc {
  40.     public:
  41.         virtual ~cd() {
  42.             cout << "deconstructor in cd !" << endl;
  43.         }

  44. };

  45. int main() {

  46.     cd cd;
  47.     cc cc;
  48.     cout << "sizeof cc is " << sizeof(cc) << endl;
  49.     cout << "sizeof cd is " << sizeof(cd) << endl;
  50.     return 0;
  51. }
復(fù)制代碼
我的機器是64位的,cc 和 cd的sizeof打印出來都是16,我理解的是 cc中包含了兩個(CA & CB)虛表的指針,但是CD呢? CD為什么也是16,CC中的虛表指針呢?



糊涂了,想不明白了,誰來指導(dǎo)一下。


作者: OwnWaterloo    時間: 2013-11-26 16:57

  1. $ g++ -fdump-class-hierarchy
復(fù)制代碼
http://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html
-fdump-class-hierarchy (C++ only)
-fdump-class-hierarchy-options (C++ only)
    Dump a representation of each class's hierarchy and virtual function table layout to a file. The file name is made by appending .class to the source file name, and the file is created in the same directory as the output file. If the ‘-options’ form is used, options controls the details of the dump as described for the -fdump-tree options.

  1. $ cl /d1reportAllClassLayout
復(fù)制代碼
http://connect.microsoft.com/Vis ... ject-layout-browser

...
In the mean time, you can use the undocumented (and unsupported) compiler switches /d1reportSingleClassLayout<class> and /d1reportAllClassLayout to get the information you want from your build. For more information on these switches, please read Andy's excellent blog post: http://blogs.msdn.com/vcblog/arc ... fixing-lnk2022.aspx

Peter-Michael Osera
Visual C++ Compiler Team

  1. $ clang -cc1 --help | grep layouts
  2.   -fdump-record-layouts   Dump record layout information
  3.   -fdump-vtable-layouts   Dump the layouts of all vtables that will be emitted in a translation unit
復(fù)制代碼
建議將代碼改成這樣再去試:

  1. class ca { public: virtual ~ca() {} };
  2. class cb { public: virtual ~cb() {} };
  3. class cc : public ca, public cb { public: virtual ~cc() {} };
  4. class cd: public cc { public: virtual ~cd() {} };

  5. int main(int argc, char* argv[])
  6. {
  7.       switch (argc)
  8.       {
  9.       default: return 0;
  10.       case 1: return sizeof(ca);
  11.       case 2: return sizeof(cb);
  12.       case 3: return sizeof(cc);
  13.       case 4: return sizeof(cd);
  14.       }
  15. }
復(fù)制代碼

作者: _BlueGuy__    時間: 2013-11-26 17:05
OwnWaterloo 發(fā)表于 2013-11-26 16:57
建議將代碼改成這樣再去試:

我們?nèi)杭尤耍阋M來嗎?

305369284

作者: OwnWaterloo    時間: 2013-11-26 17:44
回復(fù) 3# _BlueGuy__

我不做游戲、不談?wù)軐W(xué)、不玩Lua、不寫web服務(wù)器、不用學(xué)也沒什么機會用C/C++。外帶也不亂搞男女關(guān)系。
即使加進去過不了一周就會屏蔽群消息 —— 群里至少有3位能作證我這不是在亂說。
所以還是算了吧。啊。
作者: _BlueGuy__    時間: 2013-11-26 17:48
OwnWaterloo 發(fā)表于 2013-11-26 17:44
回復(fù) 3# _BlueGuy__

我不做游戲、不談?wù)軐W(xué)、不玩Lua、不寫web服務(wù)器、不用學(xué)也沒什么機會用C/C++。外帶 ...

之前不是聽說你在做網(wǎng)站?然后又在做嵌入式
作者: _BlueGuy__    時間: 2013-11-26 17:52
OwnWaterloo 發(fā)表于 2013-11-26 17:44
回復(fù) 3# _BlueGuy__

我不做游戲、不談?wù)軐W(xué)、不玩Lua、不寫web服務(wù)器、不用學(xué)也沒什么機會用C/C++。外帶 ...

屏蔽群消息沒關(guān)系,我們?nèi)夯静徽f話
作者: _BlueGuy__    時間: 2013-11-26 17:55
OwnWaterloo 發(fā)表于 2013-11-26 17:44
回復(fù) 3# _BlueGuy__

我不做游戲、不談?wù)軐W(xué)、不玩Lua、不寫web服務(wù)器、不用學(xué)也沒什么機會用C/C++。外帶 ...

只要你自己不退群,我們就不T你,
我們?nèi)汉茏鹬厝瞬?hr noshade size="2" width="100%" color="#808080"> 作者: _BlueGuy__    時間: 2013-11-27 12:23
OwnWaterloo 發(fā)表于 2013-11-26 17:44
回復(fù) 3# _BlueGuy__

我不做游戲、不談?wù)軐W(xué)、不玩Lua、不寫web服務(wù)器、不用學(xué)也沒什么機會用C/C++。外帶 ...


我們整個群都是寫游戲的

我們的游戲 客戶端是用Lua寫的,服務(wù)器是 c/c++寫的,
游戲的目標是向最終的用戶倡導(dǎo)先進哲學(xué)思想,健康的人生觀、價值觀、世界觀
游戲內(nèi)容滲透了愛恨情仇
作者: syre    時間: 2013-11-27 13:10
你把ca和cd也都打出來看看

作者: mci2004    時間: 2013-11-27 14:12
回復(fù) 2# OwnWaterloo


    謝謝!




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2