Talk about the meaning of C + + pure virtual function!

Source: Internet
Author: User

What is the meaning of the existence of pure virtual function? I believe that if there is a C + + course in the university, when it comes to pure virtual function, it will be said that pure virtual function is the basis of interface-oriented programming.

Now and you share the pure virtual function design of the original, the purpose, the effect of production.


Modern software engineering is very large, so there are a variety of technologies to solve the problem.

Modern software is made up of a variety of basic libraries, bottom-level libraries, communication libraries and so on, and its own business will be divided into various modules.

The collaboration between the various modules introduces the technique of pure virtual function.

Why use this technique:

Q: The A module is developed and depends on the B module, but the B module has not yet been developed and has only one set of interfaces. What happens if there is no pure virtual function?

The compilation of a module will fail. The C language avoids this problem by means of an empty implementation of the interface. But the problem is neither beautiful nor convenient to solve.

Therefore, C + + introduces the existence of virtual functions, and with the polymorphic characteristics, the perfect solution to this problem.

The pure virtual function solves the need to modify any code, even if only the interface can be compiled and the dependencies between multiple modules are not modified.

Explanation: When compiling, the compiler will find the function definition according to the function declaration. If there is no definition, the compilation fails.


Benefits:

The introduction of pure virtual function, C + + interface-oriented programming is very beautiful, and multi-state object-oriented programming in the cross-module programming to the Duck.


Off Topic:

Interface-oriented programming is one of the six definitions of software engineering, so it is so important that Java defines the interface class on the basis of pure virtual function. Interface-oriented programming is more clearly supported.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Talk about the meaning of C + + pure virtual function!

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.