首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

请教虚函数表放在哪里

2012-02-11 
请问虚函数表放在哪里?test1:base.h:classbase_c...{public:virtual~base_c()...{}virtualintgetkind()...

请问虚函数表放在哪里?
test1:    
base.h:    
 
class     base_c    
...{    
public:    
              virtual     ~base_c()     ...{}    
              virtual     int     getkind()     ...{return     0;}    
};    
 
class     derive:     public     base_c    
...{    
public:    
              virtual     int     getkind()     ...{return     1;}    
};    
 
  derived1.cpp:    
 
#include     "base.h "    
 
int     f1()    
...{    
              derive*     pD1=new     derive();    
              base_c*     pB=new     base_c();    
              int     nRet=pD1-> getkind()+pB-> getkind();    
              delete     pD1;    
              delete     pB;    
 
              return     nRet;    
}    
 
derived2.cpp:    
 
#include     "base.h "    
 
int     f2()    
...{    
derive*     pD2=new     derive();    
base_c*     pB=new     base_c();    
int     nRet=pD2-> getkind()+pB-> getkind();    
delete     pD2;    
delete     pB;    
 
return     nRet;    
}    
 
>     nm     derive1.o    
 
00000000     W     _._6base_c    
00000000     W     _._6derive    
00000000     W     __6base_c    
00000000     W     __6derive    
00000000     ?     __EXCEPTION_TABLE__    
00000000     ?     __FRAME_BEGIN__    
                                  U     __builtin_delete    
                                  U     __builtin_new    
                                  U     __rethrow    
                                  U     __rtti_si    
                                  U     __rtti_user    
00000000     W     __tf6base_c    


00000000     W     __tf6derive    
00000008     C     __ti6base_c    
0000000c     C     __ti6derive    
00000000     V     __vt_6base_c    
00000000     V     __vt_6derive    
00000000     T     f1__Fv    
00000000     t     gcc2_compiled.    
00000000     W     getkind__6base_c    
00000000     W     getkind__6derive    
 
 
>     nm     derive2.o    
 
00000000     W     _._6base_c    
00000000     W     _._6derive    
00000000     W     __6base_c    
00000000     W     __6derive    
00000000     ?     __EXCEPTION_TABLE__    
00000000     ?     __FRAME_BEGIN__    
                                  U     __builtin_delete    
                                  U     __builtin_new    
                                  U     __rethrow    
                                  U     __rtti_si    
                                  U     __rtti_user    
00000000     W     __tf6base_c    
00000000     W     __tf6derive    
00000008     C     __ti6base_c    
0000000c     C     __ti6derive    
00000000     V     __vt_6base_c    
00000000     V     __vt_6derive    
00000000     T     f2__Fv    
00000000     t     gcc2_compiled.    
00000000     W     getkind__6base_c    
00000000     W     getkind__6derive    
 
test2    
base.h:    
 
class     base_c    
...{    
public:    
              virtual     ~base_c()     ...{}    
              virtual     int     getkind();    
};    
 
class     derive:     public     base_c    
...{    
public:    
              virtual     int     getkind();    
};    
 
base.cpp:    
 
#include     "base.h "    
 
int     base_c::getkind()    
...{    
              return     0;    


}    
 
int     derive::getkind()    
...{    
              return     1;    
}    
 
>     nm     base.o    
00000000     W     _._6base_c    
00000000     W     _._6derive    
00000000     ?     __FRAME_BEGIN__    
                                  U     __builtin_delete    
                                  U     __rtti_si    
                                  U     __rtti_user    
00000000     W     __tf6base_c    
00000000     W     __tf6derive    
00000008     C     __ti6base_c    
0000000c     C     __ti6derive    
00000000     V     __vt_6base_c    
00000000     V     __vt_6derive    
00000000     t     gcc2_compiled.    
00000000     T     getkind__6base_c    
00000010     T     getkind__6derive    
 
 
>     nm     derive1.o    
 
00000000     W     __6base_c    
00000000     W     __6derive    
00000000     ?     __EXCEPTION_TABLE__    
00000000     ?     __FRAME_BEGIN__    
                                  U     __builtin_delete    
                                  U     __builtin_new    
                                  U     __rethrow    
                                  U     __vt_6base_c    
                                  U     __vt_6derive    
00000000     T     f1__Fv    
00000000     t     gcc2_compiled.    
 
 
  >     nm     derive2.o    
 
00000000     W     __6base_c    
00000000     W     __6derive    
00000000     ?     __EXCEPTION_TABLE__    
00000000     ?     __FRAME_BEGIN__    
                                  U     __builtin_delete    
                                  U     __builtin_new    


                                  U     __rethrow    
                                  U     __vt_6base_c    
                                  U     __vt_6derive    
00000000     T     f2__Fv    
00000000     t     gcc2_compiled.    
--------------------------------------------------------    
 
q1:     vitual     function     会被拒绝     inline化,那么它的定义在哪里?    
 
q2:     complier一般将vtbl放在第一个没有inline的vitual     function的定义得编译单元内,如所有的virtual     function都inline了,vtbl放在哪里?    
 
q3:     哪位高手能帮我解读nm的symbol信息阿?__6base_c,     __vt_6base_c,     __tf6base_c,     __ti6base_c,     _._6base_c     都各代表什么呀?    

第一个问题我想答案应该是虚函数和一般函数一样被拒绝inline后会在每个编译单元内插入一份实现?    


[解决办法]
指向代码所在的编译单元的那个。
[解决办法]
周意楼上。
但连接器最终应该有能力消除重复。

热点排行