More Effective C study notes VI: Miscellaneous

1. In the future development of the program state

  • With c ++ language to express constraints on the design, rather than using a comment or a document.
  • Note that virtual destructor
  • and many more

 

2. The non-leaf class is designed to abstract class

3. How to use c ++ and c mixed in the same program

 

  • Ensure that a compatible obj file
  • Name conversion

Because c no function overloading, so there is no name transformation, displays all need to tell c ++ compiler can not be converted to a function name in other languages,

Use extern indicating 'C'. Not only indicates the c language,

_Cplusplus only by macro defined in c ++ compiler

#ifdef _cplusplus
extern "C"{
#endif
    void drawLine(int x1, int y1, int x2, int y2);
    void twiddleBits(unsigned char bits);
    void simulate(int iterations);

#ifdef _cplusplus
}
#endif
  • Static initialization

If you have a static object c ++ program, it is recommended to use c ++ main function.

  • Dynamic memory allocation

new delete    和 malloc free

  • Compatibility Data Structure
Published 44 original articles · won praise 5 · Views 1391

Guess you like

Origin blog.csdn.net/qq_33776188/article/details/104770740