Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Difficulty: 3/10
Date added: 16th of June 2008
In this exercise, you must follow the following advice: 'Don't give away your internals' [1]. You will learn something about method design and a 'loophole' in constness.
You are programming on a Zoo class, containing a std::vector of Animal. An Animal is an ordinary struct containg member variables only (also called a plain old data type). Your code so far is shown below.
#include <vector> |
Write a method called 'GetAnimals' to read, and only read, the std::vector of Animal.
View the answer of this exercise.
You still work on the same Zoo and Animal class. But you redesigned Animal to be an abstract base class. You have decided to store pointers to Animal in a boost::shared_ptr. Your redesigned code is shown below.
#include <vector> |
Write a method called 'GetAnimals' to read, and only read, the std::vector of boost::shared_ptr of Animal. Check this method.
View the answer of this exercise.
Feedback can be posted at the Programmer's Heaven page about this article.
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.