[ 学习笔记 ] Effective C++ :Item 1

[ 学习笔记 ] Effective C++ :Item 1
Item 1:View C++ as a federation of languages
 
Item 1:将C++视为语言的联合体
 
------------------- Chinese -------------------
 
最初,C++仅仅是在C的基础上附加了一些面向对象的特征。但是,随着C++的成长发展,C++已经成为了一个多范式的编程语言,一个囊括了过程化,面向对象,函数化,泛型以及元编程特性的联合体。可以将它分成4个部分:
 
C ------ 归根结底,C++依然是基于C的。模块,语句,预处理器,内建数据类型,数组,指针等,全都来自于C。只是在很多方面,C++提出了更高级的解决问题的方法。
 
Object-Oriented C++ ------ C++的这部分就是C with Classes 涉及到的全部:类(包括构造函数和析构函数),封装,继承,多态,虚函数(动态邦定)等。C++的这一部分直接适用于面向对象设计的经典规则。
 
Template C++ ------ 这是C++的泛型编程部分。
 
STL ------ STL是一个特殊的模板库。它将容器,迭代器,算法和函数对象优雅的整合在一起。
     
头脑中保持这四个子语言,从一种子语言转到另一种时,为了高效编程,需要改变策略:
 
      例如,适用内建(类C的)类型时,传值通常比传引用更高效,但是当从C++的C部分转到C++的Object-Oriented部分,用户自定义构造函数和析构函数意味着更好的做法是将引用传递给const参数。在 Template C++ 中工作时,这一点更加重要,因为,在这种情况下,你甚至不知道你的操作涉及到的对象的类型。当你进入 STL,无论如何,你知道迭代器和函数对象以 C 的指针为原型,对于 STL 中的迭代器和函数对象,古老的 C 中的传值规则又重新生效。
 
***********************************************************
 
Things to Remember:
 
      高效C++编程规则的变化,依赖于你使用C++的哪一个部分。
 
 
 
 
 
------------------- English --------------------
 
In the beginning, C++ was just C with some object-oriented features tacked on. As the language matured, C++ have become a multiparadigm programming language, one suppoting a combination of procedural, object-oriented, functional, generic, and metaprogramming features.
 
There are four parts in the C++:
 
C ------ Way down deep, C++ is still based on C. Blocks, statements, the preprocessor, built-in data types, arrays, pointers,etc, all come from C. In many cases, C++ just offers approaches to problems that are superior to their C counterparts.
 
Object-Oriented C++ ------ This part of C++ is what C with Classes was all about: classes(including constructors and destructors), encapsulation, inheritance, polymorphism, virtual functions(dynamic binding),etc. This is the part of C++ to which the classic rules for object-oriented design most directly apply.
 
Template C++ ------ This is the generic programming part of C++.
 
The STL ------ The STL si avery special template library. Its conventions regarding containers, iterators, algorithms, and function objects mesh beautifully.
 
Keep these four sublanguages in mind, and don't be surprised when you encounter situations where effective programming requires that you change strategy when you switch from one sublanguage to another.
 
For example, pass-by-value is generally more efficient than pass-by-reference for built-in (i.e., C-like) types, but when you move from the C part of C++ to Object-Oriented C++, the existence of user-defined constructors and destructors means that pass-by-reference-to-const is usually better. This is especially the case when working in Template C++, because there, you don't even know the type of object you're dealing with. When you cross into the STL, however, you know that iterators and function objects are modeled on pointers in C, so for iterators and function objects in the STL, the old C pass-by-value rule applies again.  
 
**********************************************************
 
Things to Remember
 
Rules for effective C++ programming vary, depending on the part of C++ you are using!


马嘉楠
[email protected]

你可能感兴趣的:([ 学习笔记 ] Effective C++ :Item 1)