Does compiler generate vtable for a class that is not used

Saravanan

Can you explain does compiler generates vtable for a class which has virtual function and there is no use of that class(object not created in any sort). Say for ex,

    class A {
          public:
           virtual void func() { }
    };
    int main()
    {
       return 0;
    }

For the above program does compiler creates vtable for the class A? It may be a duplicate question, but i wanted to know the solution. If it is duplicate please provide the link to the source.

tenfour

The concept of a vtable is an implementation detail, and not part of the C++ standard. When a vtable is needed by your compiler, one is created.

In your case, the class is never used, and compilers won't generate any code at all.

But even if you instantiate the class and call functions with side-effects, if you never use features that necessitate a vtable, one does not need to be generated.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Does compiler generate vtable for a class that is not used

From Dev

Why derived class does not have the vtable pointer and used instead vtable of the base class?

From Dev

How does the compiler know which entry in vtable corresponds to a virtual function?

From Dev

Why does the Rust compiler generate huge executables?

From Dev

Why does the PureScript compiler generate lots of "| 0"

From Dev

Changing the VTable of an external Class

From Dev

how does compiler know that the class being used is a generic one although it has been compiled and its type erased to pre-generic code

From Dev

Does order of method declarations in a class matter to the compiler?

From Dev

Forcing the compiler to generate code for all member functions of a template class?

From Dev

undefined reference to 'vtable for class' constructor

From Dev

Obtain the vtable of a class without an object

From Dev

Compiler error with unordered_map when used in template class

From Dev

How does the compiler generate code for virtual function calls?

From Dev

Why does compiler generate additional sqrts in the compiled assembly code

From Dev

Why does the compiler automatically generate a Debugger attribute for anonymous type?

From Dev

Why does golang compiler think the variable is declared but not used?

From Dev

Why does compiler need complete type when reference is used?

From Dev

Does C compiler allocates memory for variable name used for declaring an array?

From Dev

What algorithm is used by eclipse to generate verison id in Serializable class?

From Dev

Java - compiler error - enum defined in a class cannot be used for generic substitution in the same class

From Dev

C++ , Why Base class needs a VTable

From Dev

Can the class have more than one vtable?

From Dev

Class does not exist when using service inside compiler pass

From Dev

Why does not capitalizing the class name cause a compiler error here?

From Dev

Why does the compiler claim this class method has no return value?

From Dev

Shouldn't the compiler warn me that class does not respond to copyWithZone?

From Dev

Why does the java compiler give "rawtypes" warning for class literal?

From Dev

C++ compiler does not detect error in class template

From Dev

Why does the java compiler create a synthetic constructor in outer class?

Related Related

  1. 1

    Does compiler generate vtable for a class that is not used

  2. 2

    Why derived class does not have the vtable pointer and used instead vtable of the base class?

  3. 3

    How does the compiler know which entry in vtable corresponds to a virtual function?

  4. 4

    Why does the Rust compiler generate huge executables?

  5. 5

    Why does the PureScript compiler generate lots of "| 0"

  6. 6

    Changing the VTable of an external Class

  7. 7

    how does compiler know that the class being used is a generic one although it has been compiled and its type erased to pre-generic code

  8. 8

    Does order of method declarations in a class matter to the compiler?

  9. 9

    Forcing the compiler to generate code for all member functions of a template class?

  10. 10

    undefined reference to 'vtable for class' constructor

  11. 11

    Obtain the vtable of a class without an object

  12. 12

    Compiler error with unordered_map when used in template class

  13. 13

    How does the compiler generate code for virtual function calls?

  14. 14

    Why does compiler generate additional sqrts in the compiled assembly code

  15. 15

    Why does the compiler automatically generate a Debugger attribute for anonymous type?

  16. 16

    Why does golang compiler think the variable is declared but not used?

  17. 17

    Why does compiler need complete type when reference is used?

  18. 18

    Does C compiler allocates memory for variable name used for declaring an array?

  19. 19

    What algorithm is used by eclipse to generate verison id in Serializable class?

  20. 20

    Java - compiler error - enum defined in a class cannot be used for generic substitution in the same class

  21. 21

    C++ , Why Base class needs a VTable

  22. 22

    Can the class have more than one vtable?

  23. 23

    Class does not exist when using service inside compiler pass

  24. 24

    Why does not capitalizing the class name cause a compiler error here?

  25. 25

    Why does the compiler claim this class method has no return value?

  26. 26

    Shouldn't the compiler warn me that class does not respond to copyWithZone?

  27. 27

    Why does the java compiler give "rawtypes" warning for class literal?

  28. 28

    C++ compiler does not detect error in class template

  29. 29

    Why does the java compiler create a synthetic constructor in outer class?

HotTag

Archive