For C Programmer's Advice (learning C + +)

Source: Internet
Author: User
Tags data structures

From C + + programming language 1.6.1 translation is not good please advise

For C Programmer's advice

The more familiar a person is with C, the more difficult it is to avoid writing C + + programs. As a result, some of the potential benefits of C + + are lost. See Appendix B, which describes the differences between C and C + +. Here are a few of the programs that use C + + mode better than the C program model.
1. Macros are never necessary in C + +, use const or enum to define static variables, use inline to avoid function call overhead, template to point to function and type family, namespace avoid naming conflicts.
2. Do not declare it before using a variable (translator, do not declare in advance, when to use when to declare, and immediately initialize). The declaration should be in any place (translator, compared to c), included in the for and if conditions.
3. Don't use the malloc (), the new operator to do the same thing, and do it better. Instead of realloc (), you can try vectors.
4. Try to avoid void*, pointer algorithms (pointer arithmetic), union (Union) and styling (cast is type conversion). In most cases modelling is the performance of faulty design. If you have to force type conversions, try "new casts" because you're doing it in a more precise state.
5. By reducing the use of character arrays in C mode, the C + + standard class library provides string and vector classes that simplify programs (compared to traditional C schemas) and, in general, do not write your own programs to implement functionality already in the standard library.
To accommodate C's join custom, C + + functions must be declared as C join mode.
Most importantly, try to see a program as an interaction concept (translator: Member and method). and is displayed as classes and instances rather than as a bunch of data structures manipulated by functions.

Related Article

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: 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.