⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ei4.htm

📁 一个非常适合初学者入门的有关c++的文档
💻 HTM
字号:
 Effective C++, 2E | Item 4: Prefer C++-style comments Back to Item 3: Prefer new and delete to malloc and free.Continue to Memory ManagementItem 4: Prefer C++-style comments.The good old C comment syntax works in C++ too, but the newfangled C++ comment-to-end-of-line syntax has some distinct advantages. For example, consider this situation: if ( a > b ) {  // int temp = a;    // swap a and b  // a = b;  // b = temp;}Here you have a code block that has been commented out for some reason or other, but in a stunning display of software engineering, the programmer who originally wrote the code actually included a comment to indicate what was going on. When the C++ comment form was used to comment out the block, the embedded comment was of no concern, but there could have been a serious problem had everybody chosen to use C-style comments: if ( a > b ) {  /*  int temp = a;  /* swap a and b */      a = b;      b = temp;  */}Notice how the embedded comment inadvertently puts a premature end to the comment that is supposed to comment out the code block.C-style comments still have their place. For example, they're invaluable in header files that are processed by both C and C++ compilers. Still, if you can use C++-style comments, you are often better off doing so.It's worth pointing out that retrograde preprocessors that were written only for C don't know how to cope with C++-style comments, so things like the following sometimes don't work as expected: #define LIGHT_SPEED   3e8    // m/sec (in a vacuum)Given a preprocessor unfamiliar with C++, the comment at the end of the line becomes part of the macro! Of course, as is discussed in Item 1, you shouldn't be using the preprocessor to define constants anyway. Back to Item 3: Prefer new and delete to malloc and free.Continue to Memory Management 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -