Initial understanding of static and dynamic linking.

Source: Internet
Author: User

Polymorphism:

    1. Static-Union polymorphism (compile-time polymorphism) implemented by overloads of functions, operators (the system compiles polymorphism based on the number of parameters)
    2. Dynamic Union polymorphism (runtime polymorphism) through inheritance, virtual functions (when the runtime can implement objects and functions)C + +: Dynamic linking is implemented with the support of virtual function

Condition: A base class pointer to a derived class object or reference to a base class reference to a derived class object (calling a virtual function)

Dynamic linking:

1#include <iostream>2     using namespacestd; 3     classshape{4        Public:  5         void VirtualDraw () {cout<<"I am Shape"<<endl;}//This sets the draw to be a virtual function.6         voidFun () {Draw ();} 7     }; 8     classCircle Publicshape{9        Public:  Ten         voidDraw () {cout<<"I am Circle"<<endl;}//Although it is not stated that draw in the Circle class is a virtual function, circle actually inherits the virtual nature One     };  A     voidMain () { - Circle Oneshape;  - Oneshape.fun ();  the}

Without virtual, the program will output I am circle, because the virtual function is bound, if not, the output is I am shape; to get to the list, you have to learn the data structure and the Assembly,

In fact, the essence of virtual function is to make a data structure. that is, the virtual function table

Initial understanding of static and dynamic linking.

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.