小编Bru*_*lon的帖子

在派生类中调用sizeof(*this)

如果我有两个类,BAA的特化,有一个非虚函数叫做size:

class A
{
  unsigned Size() {return sizeof(*this);}
}

class B: public A;
Run Code Online (Sandbox Code Playgroud)

当我从B调用Size函数时,它会返回B的大小还是A的大小?我假设B,因为this关键字会为每个关键字评估不同的东西,但我不确定.

c++ inheritance this specialization

1
推荐指数
1
解决办法
51
查看次数

标签 统计

c++ ×1

inheritance ×1

specialization ×1

this ×1