Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Difficulty: 2/10
Date added: 30th of March 2011
This exercise shows that working with smart pointers is not always easy...
This exercise is a continuation on Exercise #10: Obtaining a read-only (smart?) pointer.
Following Exercise #10: Obtaining a read-only (smart?) pointer a programmer has written the following class:
#include <boost/checked_delete.hpp> |
Writing such a class enables safe forward declarations and forces the user of this class to use smart pointers, which is a good thing [1].
This programmer wants to use a class managing a std::vector of boost::shared_ptr of MyStruct, but he/she also wants to let the user obtain a std::vector of read-only smart pointers/pointers, that can be copied freely.
The code below shows the choices and some lines that should and should not compile:
#include <vector> |
What should the question marks be?
View the answer of this part of the exercise
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.