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

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2127 | 回復(fù): 9
打印 上一主題 下一主題

[C++] C++的虛表到底是怎么玩的?求指教 [復(fù)制鏈接]

論壇徽章:
3
摩羯座
日期:2013-11-12 20:06:19午馬
日期:2013-11-27 16:35:55雙魚座
日期:2014-04-04 19:02:30
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2013-11-26 09:35 |只看該作者 |倒序瀏覽
  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)一下。

論壇徽章:
2
青銅圣斗士
日期:2015-11-26 06:15:59數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-07-24 06:20:00
2 [報告]
發(fā)表于 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ù)制代碼

論壇徽章:
4
摩羯座
日期:2013-11-24 21:55:03天秤座
日期:2013-11-25 20:54:14酉雞
日期:2013-11-26 22:08:11天蝎座
日期:2013-12-07 07:32:45
3 [報告]
發(fā)表于 2013-11-26 17:05 |只看該作者
OwnWaterloo 發(fā)表于 2013-11-26 16:57
建議將代碼改成這樣再去試:

我們?nèi)杭尤,你要進來嗎?

305369284

論壇徽章:
2
青銅圣斗士
日期:2015-11-26 06:15:59數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-07-24 06:20:00
4 [報告]
發(fā)表于 2013-11-26 17:44 |只看該作者
回復(fù) 3# _BlueGuy__

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

論壇徽章:
4
摩羯座
日期:2013-11-24 21:55:03天秤座
日期:2013-11-25 20:54:14酉雞
日期:2013-11-26 22:08:11天蝎座
日期:2013-12-07 07:32:45
5 [報告]
發(fā)表于 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)站?然后又在做嵌入式

論壇徽章:
4
摩羯座
日期:2013-11-24 21:55:03天秤座
日期:2013-11-25 20:54:14酉雞
日期:2013-11-26 22:08:11天蝎座
日期:2013-12-07 07:32:45
6 [報告]
發(fā)表于 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話

論壇徽章:
4
摩羯座
日期:2013-11-24 21:55:03天秤座
日期:2013-11-25 20:54:14酉雞
日期:2013-11-26 22:08:11天蝎座
日期:2013-12-07 07:32:45
7 [報告]
發(fā)表于 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)汉茏鹬厝瞬?/td>

論壇徽章:
4
摩羯座
日期:2013-11-24 21:55:03天秤座
日期:2013-11-25 20:54:14酉雞
日期:2013-11-26 22:08:11天蝎座
日期:2013-12-07 07:32:45
8 [報告]
發(fā)表于 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)容滲透了愛恨情仇

論壇徽章:
0
9 [報告]
發(fā)表于 2013-11-27 13:10 |只看該作者
你把ca和cd也都打出來看看

論壇徽章:
3
摩羯座
日期:2013-11-12 20:06:19午馬
日期:2013-11-27 16:35:55雙魚座
日期:2014-04-04 19:02:30
10 [報告]
發(fā)表于 2013-11-27 14:12 |只看該作者
回復(fù) 2# OwnWaterloo


    謝謝!
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP