C ++ 01) Character introduction:Master C ++: has ten years of C ++ development experience. In recent years, he has transferred to the company for project management and employee training. He has completed C ++ language, system design and planning, and project management, employee Training is well known. In addition to teams, the company is often responsible for training employees and occasionally giving small lessons to answer questions from junior programmers. Xiao Cai: The Current embedded system engineer is a daily user of the assembly language/C language. I have developed a program for three years and want to improve my skills. Sub-accounts:Cai is a master of C language and recently participated in one of the projects, which requires C ++. The C ++ language is unfamiliar and familiar to Cai. Familiar with basic syntax, unfamiliar with the object-oriented syntax section in C ++. This makes Mr. Cai very painful. For him, the C language is much more advanced than the assembly language, and he has always thought that the C language is a perfect language. On this day, Mr. Cai heard that the company has a project manager. He used to be a C language master, but he is very fond of C ++. So he decided to ask the master C ++ to learn how to learn C ++. Show the story. C ++, a much simpler ProgramAfter a while, the programmer's nature was revealed, and CAI began to ask questions directly. Cai: You said, What should I learn from my current situation? MASTER: Ah, um, huh ...... C ++. Cai: You have always advised me to learn C ++, which we really cannot use during development. After all, not all projects require C ++. MASTER: when we beat people, we all saw tricks. What worked was actually internal strength. Cai: Isn't C ++ a new approach? MASTER: neither. As far as your current situation is concerned, the most skillful weapon is of course the best weapon. However, on the one hand, I think there are still many fields in embedded system development that will be dominated by C ++ in the future. For example, many projects in our company have begun to adopt C ++. On the other hand, if you have an object-oriented development idea, you can use C language to develop good programs. Cai: you are tired. The master put down his books. Smile in your eyes. MASTER: This is really the right person. In your code, at least 10 items use the features of C ++. For example, for new for statement usage, const defines parameters ...... Xiao Cai: Well, the last induction training. You have already told us in detail that as long as my compiler has these useful features, I don't care whether it is C or C ++. MASTER: Oh, it seems that you don't know how powerful C ++ is. Xiao Cai: that is, I know how to brag. MASTER: Go, take the paper. Mr. Cai picked up the paper and pen, and the master started to give lectures. MASTER: You know, I have been playing C language for many years before I started to access object-oriented and C ++. To say that C ++ is better than C, the first one is that after the program grows and becomes a large program, the development effect of C ++ is better. In this regard, I have a lot of experience, because I often think about it when using C ++. What should I do if I use C? Therefore, I am the most qualified to tell you why C programmers must learn C ++. Xiao Cai: Don't blow it. Quick example. MASTER: Well, my experience is a big example. 1. Remember. MASTER: Didn't you use this example in your debugging code last time? You need to output some information to the screen to verify that your program is running correctly. Use C ++ to do so. The master writes a program on the paper: class Trace {public: int deprint (char * s)} Master: Look, we define a class for you to debug the code, output prompt. How do you use C language? Cai: We use macros. MASTER: Well, smart practices are probably the only use of Macros in the C ++ era. However, you can see that when we need to control whether to output data, C ++ does this: class Trace {public: Trace () {noisy = FALSE ;} int deprint (char * s) {if (noisy) printf (......);} Int on (); int off (); private: bool noisy;} is the code grown. In comparison, we use on and off for control. This is more intuitive than macro. Cai: I understand it. Logically, it is intuitive to use macros. However, if the code is implemented in C language, it is a bit confusing and not clear. Cai wrote down on the paper and implemented it in C language. MASTER: By the way, the highlights are still coming. If the program is still growing, how do you print the information to other places, for example, output to a file? Cai :...... Really, it's very troublesome. MASTER: zookeeper, which is the essence of C ++. You can see: class Trace {public: Trace (FILE * newf) {noisy = FALSE; f = newf} int deprint (char * s) {if (noisy) printf (......);} Int on (); int off (); private: bool noisy; FILE * f; // note here } You see, when using C language, you can use C ++ to add only one object to describe the data and modify the output object, which is very simple. Xiao Cai: This case is amazing. The master smiled awkwardly: There are many project cases here, and you are in Baoshan. Let me talk to you slowly.