C/C ++: callback function and class declaration

Source: Internet
Author: User

1. Callback Function (from Baidu encyclopedia)

Why should I use a callback function?

Callback can be used in the notification mechanism. For example, if you want to set a timer in program a, program A will be notified at a certain time, but the implementer of the notification mechanism knows nothing about program. Then, a function pointer with a specific prototype is required for callback to notify program a that the event has occurred. In fact, the settimer () API uses a callback function to notify the timer. If the callback function is not provided, a message is sent to the Message Queue of the program.

Another API function that uses the callback mechanism is enumwindow (), which enumerates all the top-level windows on the screen. Each window can call the functions provided by another program through it, and transfer the processing program of the window. For example, if the caller returns a value, iteration continues. Otherwise, exit. Enumwindow () does not care about where the caller is or what the handler passed by the caller is. It only cares about the returned value because it will continue to execute or exit based on the returned value.

In any case, the callback function continues from the C language. In C ++, the callback function should be used only when an interface is established with C code or when dealing with an existing callback interface. In addition to the above cases, the virtual method or function operator should be used in C ++, rather than the callback function.


2,

// Blmgxfixmaincontroller. h

Class bshmmessagerecord;
Class bshmorderdetailrecord;

Class blmgxfixmaincontroller: Public blmterminalmaincontroler {}
What is the difference between declaring other classes in blmgxfixmaincontroller. h and header files containing other classes?
Why do I call other classes in declarative mode?

The header file only needs to declare a class. If the function declaration only needs to use a class pointer or reference it, You can declare this class. The header file can contain it in the CC file.

I also see the online explanation, for example, bshmmessagerecord. h already contains blmgxfixmaincontroller. H, so the class bshmmessagerecord method is used in blmgxfixmaincontroller. h? Is that true?

If you only declare it, the problem of mutual inclusion can be solved.

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.