Programming in C++
Exercise Sheet 6
- Copy the file pets.cc containing the pet classes from the lectures (with additions)
into a new directory. Add a small main function and compile the program.
- Move the definition of the speak method from class Dog outside of the class, and get the
result to compile.
- Try declaring a variable of type Pet. As described in the lectures, this is not allowed: see if
you can make sense of the error message the compiler gives.
- Try redefining the speak method in class Dalmatian, and verify that your new version
works.
- If you copy a Dalmatian object into a Dog object, what version of speak does the resulting
object have?
- Declare a vector of pointers to Pets and add some pointers to it (using either & or new).
Loop over the vector calling speak on each pet.
- Repeat the previous question, this time using a list instead of a vector, and using an
iterator to traverse the list.