Reading Notes: C ++ programming principles and practices (ch27: differences between C and C ++) [++]

Source: Internet
Author: User

Chapter 2 C Language

1. C and C ++




2. Compatibility between C and C ++



3. c ++ features not supported by C




 

4. Differences between functions and C ++ in C: function Overloading is not supported.


5. function parameter check




6. Function Definition




 

7. Call C in C ++ and call C ++ in C



 


 

8. function pointer


View code /*

//

// This is example code from Chapter 27.2.4 "pointers to functions"

// "Programming -- Principles and Practice Using C ++" by Bjarne stroustrup

//

*/

/*----------------------------------------------------------------------------*/

Struct shape1 {

Enum kind {circle, rectangle} kind;

/*...*/

};

/*----------------------------------------------------------------------------*/

Void draw (struct shape1 * P)

{

Switch (p-> kind ){

Case circle:

/* Draw as circle */

Break;

Case rectangle:

/* Draw as rectangle */

Break;

}

}

/*----------------------------------------------------------------------------*/

Int F (struct shape1 * pp)

{

Draw (PP );

/*...*/

}

/*----------------------------------------------------------------------------*/

Typedef void (* pfct0) (struct shape2 *);

Typedef void (* pfct1int) (struct shape2 *, INT );

/*----------------------------------------------------------------------------*/

Struct shape2 {

Pfct0 draw;

Pfct1int rotate;

/*...*/

};

/*----------------------------------------------------------------------------*/

Void draw1 (struct shape2 * P)

{

(P-> draw) (p );

}

/*----------------------------------------------------------------------------*/

Void rotate (struct shape2 * P)

{

(P-> rotate) (p, 90 );

}

/*----------------------------------------------------------------------------*/

Int F1 (struct shape * pp)

{

Draw (PP );

/*...*/

}

/*----------------------------------------------------------------------------*/

9. Differences in the C/C ++ structure signature Space


 

10. Differences in keywords between C/C ++


11. Differences in variable definition between C/C ++



12. C style type conversion



13. Void * Conversion


14. Enumeration


15. namespace


16. Dynamic Memory Allocation




 

17. cStyle string




 

18. C-style string and const



19. byte operations


20. instance: strcpy


21. style issues


22. Input and Output







23. File


24. constants and macros



25. Macro



26. Macro of Class Functions



27. Do not use syntax macros


28. Conditional compilation


 

 


 

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.