C++ Primer Plus 5 读书笔记

匆匆浏览了一遍C++ Primer 5,感觉这本非常好,非常适合刚接触C++语言学习的朋友。尤其适合刚开始学习编程语言的同学。

在另外一篇笔记中笔者提到过,自己最初接触的是清华大学出版吕凤翥的,ISBN 7-302-03321-8。而在这之前暑期实习的时候接触过,这本书的具体名字和ISDN号已经不记得了,但是它对熟悉VC环境起了很大的帮助。所以对那些刚接触计算机,没有工程概念的朋友,建议学习C++ Primer 5之前,先学习下如何建立一个基本的工程,可以参考 Linux应用程序Helloworld 工程,对C++编译的时候将编译器换成g++就可以了。


好了不说废话,刚开始浏览这本书的时候,感觉就是一本入门书籍,浅显易懂,随着C++语言的逐步介绍,书中结合实例介绍了C++的特性。

结合对 Effective C++ Second Edition 读书笔记 ,对感兴趣的部分做了简单摘要:

Chapter 4
* The ISO/ANSIC C++ Standard expanded the C++ library by adding a string class.

注释:ISO/ANSIC C++标准扩展了C++库,增加了string类。

Chapter 6
* C++ has inherited from C a handy package of character-related functions, prototyped in the cctype header file.

注释:C++继承了C语言对字符操作的函数,原型定义在#inlcude 中。

Chapter 7
* The recursive approach is sometimes called divide-and-conquer strategy.

注释:递归方法有时被称为divide-and-conquer策略。

Chapter 9
* C++ adds the ability to create named namespaces by defining a new kind of declarative region, one whose main porpose is to provide an area in which to delcare names.

注释:C++增加了一个名称域来避免全局变量冲突的问题。

Chapter 13
* Public Inheritance implements an is-a relationship.
* Private Inheritance implements an has-a releationship.
* Protected Inheritance is a variation on private inheritance.

注释1:共有继承表达“是一个”的关系。
注释2:保护继承是私有继承的一个变种。
注释3:私有继承表达“有一个”的关系。


Chapter 14
Reusing code: has-a and is-a

注释:C++代码重用的方法有两种:共有继承 和 私有继承


Chapter 15
What?
RTTI is short for RunTime Type Identification. 

Why?
a) invoke the correct version of a class method
b) keep track of objects

How?
1) The dynamic_cast operator generates a pointer to a derived type from a pointer to a base type, if possible. Otherwise, the operator returns 0, the null pointer.
2) The typeid operator returns a value identifying the exact type of an object.
3) A type_info structure holds information about a particular type.

Note1: RTTI works only for classes that have virtual functions.
Note2: Even if compiler supports RTTI, it might have that feature turned off by default. If the feature is inactive, the program may still compile but produce runtime errors.


Note: If you find yourself using typeid in an extended series of if else statements, you should check whether you should instead use virtual functions and dynamic_cast.
注释: RTTI是非常有争议的一个问题,一般来说对于面向对象的编程,应该尽量少使用,如果代码中出现大量的RTTI应用,应该引起重视。


Chapter 16
STL (Standard Template Library)
The Standard Template Library, or STL, is a C++ library of container classes, algorithms, and iterators; it provides many of the basic algorithms and data structures of computer science.



参考资料:

【1】Linux应用程序Helloworld

【2】Effective C++ Second Edition 读书笔记

【3】C++ Primer Plus 5th edition.


你可能感兴趣的:(c,读书,c++,inheritance,library,namespaces,语言)