C ++ Code Description

Source: Internet
Author: User

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.

 
 
  1. class stack {  
  2. char s[SIZE];  
  3. char* min;  
  4. char* top;  
  5. char* max;  
  6. void new();  
  7. public:  
  8. void push(char);  
  9. char pop();  
  10. };  

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.

 
 
  1. class TGDIDemoWindow : public TMDIFrame  
  2. {  
  3. public:  
  4. TGDIDemoWindow( LPSTR ATitle, LPSTR MenuName )  
  5. : TMDIFrame(ATitle, MenuName) {};  
  6. virtual void SetupWindow();  
  7. virtual void ArtyDemo( TMessage& ) =[CM_FIRST + ArtyDemoID];  
  8. virtual void Quit( TMessage& ) =[CM_FIRST + QuitID];  
  9. virtual void WMTimer( TMessage& ) =[WM_FIRST + WM_TIMER];  
  10. virtual void WMDestroy( TMessage& ) =[WM_FIRST + WM_DESTROY];  
  11. };  

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.

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.