Skip to content

Commit a862cb2

Browse files
committed
Started Chapter 10
1 parent 7e044b2 commit a862cb2

21 files changed

+111
-80
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
> *cppHusky* 的2024年礼
44
5-
### 此项目第一阶段计划(泛讲篇前七章)已经完成!
5+
此项目第一阶段计划(泛讲篇前七章)已经完成!
66

7-
当前进度:泛讲篇第八章完成。参见[Preview](https://github.com/cppHusky/cppHusky-cpp-Tutorial/releases/tag/preview)
7+
### 当前进度:泛讲篇第九章完成。参见[Preview](https://github.com/cppHusky/cppHusky-cpp-Tutorial/releases/tag/preview-0-0-9)
88

99
我为此规划了一个大致的编章结构,参见[Structure.md](https://github.com/cppHusky/cppHusky-cpp-Tutorial/blob/main/Structure.md)
1010

Structure.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,17 +667,17 @@
667667

668668
## 继承中的常见问题
669669

670-
### 动态类型转换 `dynamic_cast`
670+
### 继承中的类型转换
671671

672672
这一节很重要。
673673

674-
向上继承和向下继承如何实现
674+
向上类型转换和向下类型转换如何实现
675675

676676
动态类型转换 `dynamic_cast` 又是怎么回事。
677677

678678
基类指针可以指向派生类对象;基类引用可以引向派生类对象。它们能操作哪些成员。
679679

680-
### 虚函数`virtual`
680+
### 虚函数`virtual`与多态
681681

682682
#### 编程示例:不同动物的叫声
683683

@@ -699,9 +699,9 @@
699699

700700
#### 多重继承的问题
701701

702-
在使用棱形继承时,基类的对象重复
702+
在使用棱形继承时,基类的成员重复
703703

704-
### 虚基类/虚继承
704+
### 虚继承
705705

706706
> 吐槽一下,用“虚基类”这个名字是很容易引起误解的,这个`virtual`不是基类自己拥有的属性,而是“继承关系”的属性。精讲篇会细究这个问题。
707707

generalized_part.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ \part*{泛讲篇}
88
\import{generalized_parts/}{06_custom_types_and_their_use.tex}
99
\import{generalized_parts/}{07_projecting.tex}
1010
\import{generalized_parts/}{08_a_step_forward_in_classes_and_functions.tex}
11-
\import{generalized_parts/}{09_class_inheritance.tex}
11+
\import{generalized_parts/}{09_class_inheritance.tex}
12+
\import{generalized_parts/}{10_common_problems_in_inheritance.tex}

generalized_parts/03_control_flow.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ \chapter{程序的流程控制}
88
\import{03_control_flow/}{02_choice.tex}
99
\import{03_control_flow/}{03_loop.tex}
1010
\import{03_control_flow/}{04_introduction_to_scope.tex}
11-
\import{03_control_flow/}{05_exercise_simple_calculator.tex}
11+
\import{03_control_flow/}{05_exercise_simple_calculator.tex}

generalized_parts/04_introduction_to_functions.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ \chapter{函数初步}
77
\import{04_introduction_to_functions/}{03_function_overloading.tex}
88
\import{04_introduction_to_functions/}{04_default_argument.tex}
99
\import{04_introduction_to_functions/}{05_recursion.tex}
10-
\import{04_introduction_to_functions/}{06_introduction_to_function_templates.tex}
10+
\import{04_introduction_to_functions/}{06_introduction_to_function_templates.tex}

generalized_parts/06_custom_types_and_their_use.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ \chapter{自定义类型及其使用}
2020
\import{06_custom_types_and_their_use/}{02_struct.tex}
2121
\import{06_custom_types_and_their_use/}{03_exercise_example_list.tex}
2222
\import{06_custom_types_and_their_use/}{04_union.tex}
23-
\import{06_custom_types_and_their_use/}{05_introduction_to_class.tex}
23+
\import{06_custom_types_and_their_use/}{05_introduction_to_class.tex}

generalized_parts/07_projecting.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ \chapter{代码工程}
66
\import{07_projecting/}{01_separate_compilation.tex}
77
\import{07_projecting/}{02_namespace.tex}
88
\import{07_projecting/}{03_scope_storage_duration_and_linkage.tex}
9-
\import{07_projecting/}{04_coding_style.tex}
9+
\import{07_projecting/}{04_coding_style.tex}

generalized_parts/09_class_inheritance.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ \chapter{类的继承}
55
\import{09_class_inheritance/}{01_the_concepts_of_inheritance.tex}
66
\import{09_class_inheritance/}{02_public_inheritance_and_protected_members.tex}
77
\import{09_class_inheritance/}{03_private_inheritance.tex}
8-
\import{09_class_inheritance/}{04_sequential_inheriance.tex}
8+
\import{09_class_inheritance/}{04_sequential_inheriance.tex}

generalized_parts/09_class_inheritance/03_private_inheritance.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,6 @@ \subsection*{组合方式,还是继承方式?}
297297
\item 继承方式还为多态提供了可能,我们会在下一节中讲到。
298298
\end{itemize}\par
299299
如果要我描述的话,我认为私有继承相较于组合方式来说,有点像 \lstinline@mutable@ 成员相较于普通成员——如果没有什么这方面的专门需求,就不要用它。虽说如此,但是私有继承作为一种行之有效的表示``整体与部分''关系的方式,仍是读者应知应会的内容。\par
300+
\subsection*{\lstinline@stack@ 类的初步实现代码}
301+
\lstinputlisting[caption=\texttt{Header.h}]{../code_in_book/9.1-9.2/Header.h}
302+
\lstinputlisting[caption=\texttt{Definition.h}]{../code_in_book/9.1-9.2/Definition.cpp}
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
% "Multiple inheritance ... was widely supposed to be very difficult to implement efficiently. For example, in a summary of C++ in his book on Objective C, Brad Cox actually claimed that adding multiple inheritance to C++ was impossible. Thus, multiple inheritance seemed more of a challenge. Since I had considered multiple inheritance as early as 1982 and found a simple and efficient implementation technique in 1984, I couldn't resist the challenge. I suspect this to be the only case in which fashion affected the sequence of events." -Bjarne Stroustrup
1+
\chapter{继承中的常见问题}
2+
在上一章中,我们讲解了继承的基本语法和基本概念。本章我们继续深入,以期进一步搞清楚继承概念之下的许多常见问题——
3+
\begin{itemize}
4+
\item 继承关系中的类型转换是怎么进行的?又有什么规则?\par
5+
\item 多态又是怎么一回事?虚函数到底在做什么?\par
6+
\item 如果描述基类所需要的成员比描述派生类的还要多,那怎么办?\par
7+
\item 多重继承是什么?怎么理解?又有什么用?\par
8+
\item 棱形继承关系中,基类的成员重复了怎么办?\par
9+
\end{itemize}
10+
这些问题在实际编程中很常见,所以我们需要好好研究一下,以防将来真的用的时候你突然一拍脑门说:``哎呀,我没学过这玩意。''那就有点麻烦了。\par
11+
本章的内容量非常大。硬度和第八章相仿,也请读者做好心理准备。\par
12+
\import{10_common_problems_in_inheritance/}{01_type_cast_in_inheritance_relationship.tex}
13+
\import{10_common_problems_in_inheritance/}{02_virtual_function_and_polymorphism.tex}
14+
\import{10_common_problems_in_inheritance/}{03_abstract_base_class_and_pure_virtual_function.tex}
15+
\import{10_common_problems_in_inheritance/}{04_mutiple_inheritance.tex}
16+
\import{10_common_problems_in_inheritance/}{05_virtual_inheritance.tex}

0 commit comments

Comments
 (0)