Lab - Object Creation and Destruction


Objectives


Discussion

We will look at some code examples:

We will run valgrind to show memory errors.

Using valgrind

To run valgrind do:

valgrind ./executable_file

Run valgrind on your test programs to make sure there are no memory problems or if something unusual is happening.

A Makefile can be configured to run valgrind on test programs.

Pointers and Arrays

There is a close connection between arrays and pointers.

Note how in the last example the pointer variable is used like an array once it has memory allocated.


Setup

We need to:

  1. Update the shared folder in your home directory

  2. Create a directory called object_construction in your cs23001 folder

  3. Copy array_bounds_check.cpp from the shared directory into object_construction.

  4. Create object_construction.cpp, object_construction.hpp, and object_test.cpp in the object_construction folder.


Assignment

The first part of this lab is to open array_bounds_check.cpp in an editor and read over the code. There are instructions on how to compile and run the code. There are some questions to answer about the code and the various runs.

The next part of the assignment is an excercise about constructors and assignment calls. Your job is to write a small program (a class, an implementation, and a main) that calls the copy constructor, default constructor, assignment, and destructor.

It should output a message every time one of these are called: "Called {Function}". After you've done so, we'll look at an example on the projector and aska few questions about how objects are constructed and deleted in an example written by the lab instructors.


Requirements

The following should be true when you are done, NAMES MUST MATCH EXACTLY:


URL: https://data-structures.cs.kent.edu/labs/Lab6
Last update: EST