Many programmers learn C ++ code. Some people think that C ++ is an independent language rather than a C language, directly learning C ++ doesn't have to start with C, but some people feel that C ++ is not a good programming language.
No one can tell how many different styles C ++ code can derive, but I know that many C ++ beginners are faced with C ++ code of different styles, I often mistakenly think that I have seen several completely different programming languages-this alone is enough to remind us, it is imperative to study and clarify the evolution and development rules of C ++ language styles.
Similar to the style changes of previous dynasties, the study of C ++ language style has no shortcut. We can only follow the historical context and find the source of the Code style based on the research method of "ending with a table" [1] advocated by Liu Yu in Wenxin Diao Long, explores the internal cause of style evolution and clarifies the trend and laws of technological development.
- Function Description in C ++
- Illustration C ++ Multithreading
- Notes for using C ++ Builder
- Analysis of Visual C ++ development and implementation methods
- Exploring questions about C ++
1. C with classes-an attack on the C language style
Before BjarneStroustrup adopted RickMascitti's suggestion in December 1983 and named the new language it invented as "C ++", people used CCwithClasses with classes) it is called a "dialect" that originated from the C language and has a data abstraction mechanism ". Although C with classes is essentially only a scalable language that can be converted into a traditional C language code by the pre-processing program Cpre, which is similar to the pre-processing process of Pro * C language we saw in Oracle, but it did lay the foundation for all later C ++ Code in terms of style.
- class stack {
- char s[SIZE];
- char* min;
- char* top;
- char* max;
- void new();
- public:
- void push(char);
- char pop();
- };
The Code "C with classes" is recorded in Stroustrup's "design and evolution of C ++ language". The new () in the Code is actually a stack-like constructor, which is very different from the later C ++ language. Obviously, Class C almost completely inherits the C language style. The statement in the code looks exactly the same as the C language, and the class structure is roughly the same as that in the C language.
These signs indicate that the C ++ language comes from C and is compatible with C as much as possible. This design idea not only facilitates the rapid popularization of C ++, but also facilitates the smooth development of C ++. promotion obviously benefited from the large user base of C language ), in addition, the C language style has been deeply branded with the C language, so that after a few years, when the C ++ language basically has an "independent personality, stroustrup also has to remind people to leave the C language thinking style as far as possible.
On the other hand, Stroustrup firmly rooted in Class C from the class, derivation, access control, and other object-oriented concepts borrowed by the Simula language. According to Stroustrup, the intention of introducing an object-oriented mechanism for C language is to find a "suitable tool" [2] to implement a distributed system or solve similar complex problems.
However, stroustrup binds the efficiency of C with the elegance of Simula. In fact, it has laid the seeds of "Double Character" for the C ++ language-it is hard to say that this is not the C ++ language style. diverse direct incentives.
2. I/O Stream-new image of C ++
If C ++'s native parents are C language and Simula language, then in 1984, the I/O stream technology implemented by using Operator Overloading is the First Step C ++ has taken to the new Code style.
- class TGDIDemoWindow : public TMDIFrame
- {
- public:
- TGDIDemoWindow( LPSTR ATitle, LPSTR MenuName )
- : TMDIFrame(ATitle, MenuName) {};
- virtual void SetupWindow();
- virtual void ArtyDemo( TMessage& ) =[CM_FIRST + ArtyDemoID];
- virtual void Quit( TMessage& ) =[CM_FIRST + QuitID];
- virtual void WMTimer( TMessage& ) =[WM_FIRST + WM_TIMER];
- virtual void WMDestroy( TMessage& ) =[WM_FIRST + WM_DESTROY];
- };
The above code is from the sample program in C ++ programming language written by Stroustrup. Note that the line of code connected by "<", I/O streams, variables, and character constants are cleverly connected together in the code. From a technical point of view, the introduction of this new syntax makes up for the weakness of the printf () function family in C ++ code that lacks type security mechanisms and scalability.
In terms of code style, "<" and other easy-to-understand operators greatly change the programmer's first impression on the C ++ language. When I first came into contact with the C ++ I/O Stream library, I clearly felt that, a c ++ code that tries to get rid of the constraints of the C language style is "Flowing" along with streams composed of "<" and ">"-this kind of code style has been around for more than a decade. it has shown the determination and courage of the C ++ language in creating a new image and introducing new ideas.