|
53 | 53 |
|
54 | 54 | \begin{frame}[fragile]
|
55 | 55 | \frametitlecpp[98]{Inheritance privacy and polymorphism}
|
56 |
| - \begin{block}{Only public inheritance is visible to code outside the class} |
| 56 | + \begin{block}{Only public base classes are visible to outside code} |
57 | 57 | \begin{itemize}
|
58 |
| - \item private and protected are not |
| 58 | + \item private and protected bases are not |
59 | 59 | \item this may restrict usage of polymorphism
|
60 | 60 | \end{itemize}
|
61 | 61 | \end{block}
|
|
187 | 187 | \end{itemize}
|
188 | 188 | \item they also imply extra storage and an extra indirection
|
189 | 189 | \begin{itemize}
|
190 |
| - \item practically the object stores a pointer to the correct method |
| 190 | + \item practically, the object stores a pointer to the correct method |
191 | 191 | \item in a so-called ``virtual table'' (``vtable'')
|
192 | 192 | \end{itemize}
|
193 | 193 | \end{itemize}
|
|
491 | 491 | \frametitlecpp[98]{Virtual inheritance}
|
492 | 492 | \begin{block}{Solution}
|
493 | 493 | \begin{itemize}
|
494 |
| - \item inheritance can be {\it virtual} or not |
495 |
| - \item {\it virtual} inheritance will ``share'' parents |
496 |
| - \item standard inheritance will replicate them |
| 494 | + \item inheritance can be \cppinline{virtual} or not |
| 495 | + \begin{itemize} |
| 496 | + \item \cppinline{virtual} inheritance will ``share'' parents |
| 497 | + \item standard inheritance will replicate them |
| 498 | + \end{itemize} |
| 499 | + \item most derived class will call the virtual base class's constructor |
497 | 500 | \end{itemize}
|
498 | 501 | \begin{cppcode}
|
499 | 502 | class Text : public virtual Drawable {...};
|
|
528 | 531 |
|
529 | 532 | \begin{frame}[fragile]
|
530 | 533 | \frametitlecpp[98]{Multiple inheritance advice}
|
531 |
| - \begin{block}{Do not use multiple inheritance} |
| 534 | + \begin{goodpractice}{Avoid multiple inheritance} |
532 | 535 | \begin{itemize}
|
533 | 536 | \item Except for inheriting from interfaces
|
534 |
| - \item and for rare special cases |
| 537 | + \item And for rare special cases |
535 | 538 | \end{itemize}
|
536 |
| - \end{block} |
| 539 | + \end{goodpractice} |
537 | 540 | \pause
|
538 |
| - \begin{alertblock}{Do not use diamond shapes} |
| 541 | + \begin{goodpractice}{Absolutely avoid diamond-shaped inheritance} |
539 | 542 | \begin{itemize}
|
540 | 543 | \item This is a sign that your architecture is not correct
|
541 | 544 | \item In case you are tempted, think twice and change your mind
|
542 | 545 | \end{itemize}
|
543 |
| - \end{alertblock} |
| 546 | + \end{goodpractice} |
544 | 547 | \end{frame}
|
545 | 548 |
|
546 | 549 | \begin{frame}[fragile]
|
|
556 | 559 | \end{itemize}
|
557 | 560 | \end{exerciseWithShortcut}
|
558 | 561 | \end{frame}
|
559 |
| - |
560 |
| -\begin{frame}[fragile] |
561 |
| - \frametitlecpp[98]{Virtual inheritance} |
562 |
| - \begin{alertblock}{Warning} |
563 |
| - in case of virtual inheritance it is the most derived class that calls the virtual base class's constructor |
564 |
| - \end{alertblock} |
565 |
| -\end{frame} |
0 commit comments