What is static polymorphism

0. Ask a question

What is polymorphism?

PolymorphismLiterally means multiple forms. Polymorphism is used when there is a hierarchical structure between classes and the classes are linked by inheritance.

What types of polymorphic atmospheres?

Polymorphism can be divided into static polymorphism and dynamic polymorphism.

Also known as compile-time polymorphism, during system compilation you can determine what function the program will perform. For example, function overloading, performing member functions with object names and dot operators, and the operations specified by class member operators are all static polymorphisms. Among other things, overloading differentiates between function names when creating a symbol table. This determines what function the program will perform here. The object name plus the dot operator to perform the member function and the operation specified by the class member operator are invoked through this pointer.

Here a class A is defined with a member function and an element. We extract the following assembler code of the program:

 

We can see here that it is a lea instruction to set the address of the a object directly into the eax register, which is the object's this pointer, and then use the call instruction to go to the set function to jump, which means that its assembly language code knowing where to go and what function to have is also known as static polymorphismCompile-time polymorphism

This shows that different calls are actually implemented and that this happens at runtime. So how is the end of the virtual function implemented?Assembly code and its object model

From the assembler code in the figure above, we can see that a series of pointer dereferencing processing has been performed here and the value of this pointer to be stored in eax is being finally determined. To understand this, we need to understand the subclass object model.