您的位置:首页 > 其它

The relationship of inline and virtual

2007-01-17 10:57 726 查看

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放在哪里?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐