Abstract classes and multiple inheritance in C + +

Source: Internet
Author: User
Tags multiple inheritance in c

C + + does not have the concept of an interface in Java, but an abstract class can be used to emulate an interface in Java.

Multiple inheritance on the project

Multiple inheritance in engineering development is almost non-used

The complexity of the code brought by multiple inheritance is far greater than the convenience of its code.

Multiple inheritance has disastrous consequences for code maintenance

In design, any place with multiple inheritance can be replaced by a single inheritance.

C + + supports multiple inheritance, and multiple inheritance has a ambiguity.

The ability to program for abstract classes requires elevation.

function pointers:

function type

function pointer type

Define a function pointer that points to the entry address of a function

The function name represents the entry address of the function, which is a function pointer

The effect is the same for whether the function name takes an address, because of the reason for the C history compatibility.

function pointers and array pointers are surprisingly similar

The defined type C + + compiler does not allocate memory, but if a function pointer is defined directly, the memory is allocated directly.

function pointers do function arguments:

pointers do function functions and function pointers as function parameters:

The idea of pointers to function parameters, the person who invokes the task, and the person who writes the task are decoupled by function pointers, which is the essence of the callback function.

In C + + through polymorphic mechanism, in order to generate a vptr pointer for each class object, through this vptr pointer to find a virtual function table, through the virtual function table to find the corresponding execution function of the entry address, thus realizing the polymorphic expansion.

The function pointer is the essence of the function, in advance a protocol convention, that is, the number and type of parameters, as well as the type of parameter return value. As long as the Protocol convention satisfies this type of pointer, it can be called.

Callback, that is, the function calls the underlying library, and then the underlying library calls the code you write, this is the callback.

You can find the entry address of a function in the DLL library by calling the system's API function, if you want to load the DLL file into memory.

The handle records the context information for the function run.

The underlying library provides a mechanism, not a strategy.

The concept of a handle and the concept of context

The memory allocated in the underlying library needs to be freed by invoking the API of the underlying library

Using polymorphic decoupling in C + +, the use of function pointers in the C language is used to decouple the coupling.

Do not easily increase the interface,

Abstract classes and multiple inheritance in C + +

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.