Analytic dynamic Joint (Part one)

Source: Internet
Author: User

Article Summary

Polymorphism is the main feature of C + +, and the realization of polymorphism benefits from the dynamic joint-coding technology in C + +. This paper analyzes the virtual function table of the key technology of dynamic joint-editing, and the process of analytic dynamic joint-editing is extremely technical essentials.

Key words

VTABLE virtual function of polymorphic dynamic joint coding

Article body

A discussion on the necessity of dynamic joint-editing from polymorphism

Introduce the concept of the binder before entering the topic. A binder is the process of merging modules or functions together to generate executable code, allocating memory addresses for each module or function call, and allocating the correct memory address for external access. According to the different stages of the binder, there are two different methods: static Joint and dynamic Joint compilation. In the compile phase, the function implementation and function call are associated with the static link, the static link in the compile phase must understand all functions or modules to perform the required detection of information, its choice of function is based on the object's pointer (or reference) type. On the contrary, when the program is executed, the association is called a dynamic link, and the selection of the member function is not based on the pointer or reference, but on the object type, the different object types will make different compilation results. In the C language, all of the joint is a static binder. C + + general situation in the same series is also static, but once the polymorphism and virtual functions must be used to use the dynamic of the binder.

Polymorphism is the core of object-oriented, its main idea is to use a variety of forms of ability, through a user name or user interface to complete different implementations. Usually polymorphism is simply described as "an interface, multiple implementations." In C + + it is embodied in functions and methods that access derived classes through base class pointers.

Let's look at an example of a static binder, which leads to a result we don't want.

//1.cpp
1.#include <iostream.h>
2.class shape{
3.public:
4.void draw(){cout<<"I am shape"<<endl;}
5.void fun(){draw();}
6.};
7.class circle:public shape{
8.public:
9.void draw() {cout<<"I am circle"<<endl;}
10.};
11.main(){
12.class circle oneshape;
13.oneshape.fun();
14.}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.