1. Why do we sometimes use class pointers to call class functions and sometimes use objects to call class functions?
A: ① polymorphism. After the compilation, the class object has determined which class object it can call. The class type of the function has been determined and the polymorphism cannot be implemented. The pointer determines its type only when it is running. The pointer to the parent class can point to the object of the derived class, so you can call the function of the derived class, in this way, object-oriented polymorphism can be realized (of course, there are virtual functions that have polymorphism !);
② Different scopes. When using an object to call a class function in MFC, an object is generally created immediately and then called. This object is only required to call a function at the moment. Therefore, the scope of this object is limited to this function, which is a local variable and placed in the memory stack. After the function is completed, it will be automatically released. Instead, the pointer is called, because the pointer needs to be created using new and is dynamically allocated memory, which is placed in the heap and must be explicitly manually deleted to release the pointer, so if it is not released, the scope is the whole project. For example, the non-modal display window has two options: a. The object calls the create and showwindow functions. B. the pointer calls the CREATE AND showwindow functions. However, the former disappears after a flash, and the latter can be implemented smoothly. In fact, it does not mean that the former does not display a window, but the former displays it, but immediately executes the function, and the window object is immediately released and the message is sent. The latter is not required.
2. Add const to the function. This indicates that the function cannot modify the object of the class where the function is located. That is, the member variables of the class cannot be modified in the function.
3. # define XXX \ -- indicates the line feed. Some replace macros are very long, so you need to use the line break to indicate that they are all in the same row.
4. Message ing 0-the Declaration of message ing in the header file. In fact, the two comment macros are used by the Class Wizard, the Class Wizard can know where the declaration code of the message response function is written according to the comment macro. Our custom message and message response functions do not need to be declared between two comment macros. There is afx_msg before the message response function declaration. during compilation, this macro is translated into blank space.
5. Message ing 1-When message ing is implemented in the CPP file, beginxx and endxx are available before and after message ing. This is also two macros, which implement message ing between two macros. The two macros Implement Message ing through macro defined in advance. In fact, the ing between the message and the message response function is directly added to the Message array.
6. Variables cannot be defined in the C ++ case statement, because the entire switch belongs to the same code block, not necessarily executed in each case. If it is skipped, it cannot be used later, it is the same statement block, which is a special feature of switch! The syntax is as follows!