The Foo Family ============== Definition: The Foo Family -------------------------- .. plantuml:: @startuml interface IFoo { + bar() } class AFoo { + bar() } class BFoo { + bar() } IFoo <|.. AFoo IFoo <|.. BFoo @enduml .. literalinclude:: code/the-foos.h :language: c++ :caption: :download:`code/the-foos.h` Scenario: Polymorphic Access ---------------------------- **Given the following usage:** .. literalinclude:: code/polymorphic-access.cpp :language: c++ :caption: :download:`code/polymorphic-access.cpp` **Which of the following statements is true?** .. list-table:: :align: left :header-rows: 1 * * Statement * True * * A call as shown gives the output as shown .. code-block:: console $ ./program a AFoo::bar() 42 * .. list-table:: :align: left :header-rows: 1 * * Statement * True * * A call as shown gives the output as shown .. code-block:: console $ ./program b BFoo::bar() 666 * .. list-table:: :align: left :header-rows: 1 * * Statement * True * * A call as shown will do nothing because ``foo`` is null .. code-block:: console $ ./program c ...?... * .. list-table:: :align: left :header-rows: 1 * * Statement * True * * A call as shown will likely crash because ``foo`` is null .. code-block:: console $ ./program c ...?... * .. list-table:: :align: left :header-rows: 1 * * Statement * True * * However called, the program has a memory leak * Scenario: Undefined Access -------------------------- **Given the following usage:** .. literalinclude:: code/undefined-access.cpp :language: c++ :caption: :download:`code/undefined-access.cpp` **Which of the following statements is true?** .. list-table:: :align: left :header-rows: 1 * * Statement * True * * A call as shown will cause undefined behavior .. code-block:: console $ ./program a ...?... * .. list-table:: :align: left :header-rows: 1 * * Statement * True * * A call as shown will cause undefined behavior .. code-block:: console $ ./program b ...?... * Scenario: Memory Leak --------------------- **Given the following usage:** .. literalinclude:: code/memory-leak.cpp :language: c++ :caption: :download:`code/memory-leak.cpp` **Which of the following statements is true?** .. list-table:: :align: left :header-rows: 1 * * Statement * True * * A call as shown will cause undefined behavior .. code-block:: console $ ./program a ...?... * .. list-table:: :align: left :header-rows: 1 * * Statement * True * * A call as shown will leak memory .. code-block:: console $ ./program a ...?... *