The relationship of inline and virtual

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放在哪里?

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值