Out-of-Line Virtual Method

前端 未结 1 1601
深忆病人
深忆病人 2020-12-24 05:22

What exactly is a out-of-line virtual method and why does it affect link times?

LLVM Coding Standards says

If a class is defined in a

相关标签:
1条回答
  • 2020-12-24 06:04

    The compiler must emit a vtable for classes with virtual methods. This contains the pointers to these methods. If all the virtual methods are inline (defined in the header), then the compiler doesn't know which translation unit (.cpp file) to emit the vtable within, so it emits a copy in all of them and the linker gets to deal with it. This makes extra work and bloat in the object files. If, on the other hand, a virtual function is defined out-of-line (in a .cpp), the vtable can be emitted there and thus only one copy will be emitted. The same applies to the RTTI.

    0 讨论(0)
提交回复
热议问题