Introduction to static and dynamic joint-editing in C + +

Source: Internet
Author: User

A link is a process in which a computer program is associated with itself. According to the different stages of the binder, there are two different methods: static Joint and dynamic Joint compilation.

Static binder

Static concatenation refers to the fact that the work of the binder appears at the compile-and-connect stage, which is also called an early link, because the process is completed before the program begins to run.

This kind of binder, which is done at compile time, is also called static beam. At compile time, it solves the relationship between the operation Call of the program and the execution of the operation code, and determines that the relationship is also called bundle set, and Banding is also called static beam set at compile time. Here's an example of a static binder.

  #include
   class Point
{
public:
Point(double i, double j) { x=i; y=j; }
double Area() const { return 0.0; }
private:
double x, y;
};
class Rectangle:public Point
{
public:
Rectangle(double i, double j, double k, double l);
double Area() const { return w*h; }
private:
double w, h;
};
Rectangle::Rectangle(double i, double j, double k, double l):Point(i, j)
{
w=k; h=l;
}
void fun(Point &s)
{
cout< }
   void main()
{
Rectangle rec(3.0, 5.2, 15.0, 25.0);
fun(rec);
}
   该程序的运行结果为:
   0

The output indicates that in the fun () function, the area () operation performed by the object referenced by S is associated with the implementation code of the Point::area (). This is because of the results of the static binder. In the program compile phase, the area () operation performed on the objects referenced by S can only be set to the function of the point class. As a result, the program outputs the results that are not expected. Because we expect that the area () operation performed by the object referenced by S should be set to the area () function of the Rectangl class. This is not up to the static binder.

Dynamic Joint Edit

From the above analysis of the static connection, it can be known that the compiler in the compile phase does not know exactly what function will be called, only when the program is executed to determine the function to be called, to know exactly the function of the call, it is necessary for the work to be done when the program is running, This kind of work in the program operation is called the dynamic joint, or dynamic beam set, also called the late-stage joint.

The dynamic joint is actually a dynamic identification. In the previous example, the object referenced by S in the fun () function was Banding to the point class when the static binder was previously analyzed. A dynamic binder at run time will Banding the object reference of S to the rectangle class. It is visible that the same object references S, and the class objects that are set at different stages will be different. So how do you determine if it's a static or dynamic joint? C + + stipulates that dynamic binder is implemented with the support of virtual function.

From the above analysis, we can see that both static and dynamic binder are polymorphic, and they are different in different stages to different implementations. In the example above, implementation is the selection of the polymorphism of the fun () function parameter. The parameter of the function is an object reference to a class, and static and dynamic inline and dynamic editing are actually choosing its static type and dynamic type. The binder is the choice of polymorphism for this reference.

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.