Week 3 - Pointers & Objects, Aggregation

Learning objectives

Upon finishing this week, you should be able to:

  • Write code that uses pointers and references
  • Use aggregation to build objects from other objects

Suggested pacing

Monday

Tuesday

Wednesday

  • Inheritance
  • Do CPPLab Inheritance 1
    The inheritance cpplabs are not due until next week, but you need to work on them this week to avoid week 4 being overwhelming.

Thursday

Friday

Pointers and Objects

Read 11.10.

Watch this video:

Aggregation

Read learncpp.com Ch 22.3 for the ideas behind aggregation—don't worry too much about the Teacher/Department sample they use; though the idea makes sense, their example is too stripped down to be informative. (Book Ch10.8 also talks about it, but in a very limited way).

Watch these videos:

Do the Aggregation CPPLab.

Aggregation Continued

This final video looks at using aggregation to model relationships between people and to navigate those relationships. It should give you an idea about how to attack parts of this week's assignment.

The video shows how to use the debugger to view an array that has been passed into a function (3:42 mark). You will need to use this trick a lot in future weeks.

Any time you have a variable - call it myarray that you are sure is an array, but the debugger just shows a single item, you should add a Watch to see the array. For the watch, use this syntax:

myarray, 10

Where myarray is the name of the variable that you are trying to see an array through, and 10 is the number of items you want to be shown.

Using this

Read 11.11.

Watch this video on using this:

Inheritance Basics

Inheritance is one of the fundamental tools for code reuse in object-oriented programming. It allows one class to define itself as a specialized version of another class. Learncpp.com has a nice overview of why we care about inheritance that you might want to start with.

Read 15.1-15.5. In 15.4 don't worry too much about what a destructor is and why we need them * we will hit them later.

These videos offer some tips:

Read 15.9 and watch this video about the protected access modifier:

Do CPPLab Inheritance 1

Virtual Functions

Read 15.6-15.11

These videos touch on some of the key ideas:

Do the VirtualFunctionCalls worksheet from the Files area of elearn.

Abstract Classes

Do CPPLab Inheritance 2