Search code examples
c++vtable

If there are virtual methods, is vtable is going to be created?


If I create a very simple class like this :

class A
{
  public :
    virtual void foo()
    {
    }
};

(no virtual destructor) is the compiler going to create vtable? Or are modern compilers smart enough to recognize this case (which might be a bad copy and paste) and not add virtual table for such classes?


Solution

  • The v-table is an implementation detail. Compilers that use v-tables for virtual functions will create one for this class. Those that don't, won't.