小编Eps*_*on_的帖子

编译虚拟表的时间消除?

假设我有这个层次结构:

class Super
{
 public:
    virtual void bar();
};

class Sub : public Super
{
 public:
    virtual void bar() override;
};
Run Code Online (Sandbox Code Playgroud)

尽管使用了虚拟关键词,我还有办法避免使用vtable吗?(好奇心)我已经读过一些关于编译器优化的东西,当编译期间对象被识别时消除了vtables,我不是很确定,一直在谷歌周围挖掘,但是找不到任何答案,所以它是否意味着这些?

Sub sb;
sb.bar(); //avoids vtable?
Super& sr = sb;
sr.bar(); //avoids vtable?
Super* srp = &sb;
srp->bar(); //avoids vtable? 
Run Code Online (Sandbox Code Playgroud)

c++ oop c++11

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

标签 统计

c++ ×1

c++11 ×1

oop ×1