博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[ 学习笔记 ] Effective C++ :Item 1
阅读量:6387 次
发布时间:2019-06-23

本文共 3059 字,大约阅读时间需要 10 分钟。

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!
本文转自BlogJavaOo缘来是你oO的博客,原文链接:,如需转载请自行联系原博主。

你可能感兴趣的文章
SCOM警报通知新特性:即时消息通知
查看>>
如何部署HTTPS 申请证书 安装证书
查看>>
重新定义“物联网” GreenPeak助力合作伙伴构建智能家居
查看>>
String类的学习
查看>>
linux正则表达式sed
查看>>
jenkins+docker的简单项目部署
查看>>
SQL 基础之去重和显示表结构(四)
查看>>
excel学习笔记之一
查看>>
selenium--字符串/整型问题Can't convert 'int' object to str implicitly提示解决方法
查看>>
linux内核的syslets补丁
查看>>
Python多线程threading用法
查看>>
基于Struts 2的自定义类型转换器
查看>>
禁用windows更新完成后的重启提示
查看>>
Windows启动文件的详细介绍
查看>>
持久性session连接之memcached高可用方案
查看>>
curl用法:获取网站的header头及状态码
查看>>
Linux常用的基本命令02
查看>>
[cocos2d-x]图层的旋转缩放效果
查看>>
Java实现文件拷贝
查看>>
ExtJS4.2学习(八)表格限制输入数据的类型
查看>>