Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-01-17 13:51:04

> Unfortunately, this does not work smoothly: I need to define the
> class to be used as template argument to the 'boost::shared_ptr' in the
> header to make it work. One option would be something like this:
> // directory.hpp:
> struct representation { virtual ~representation(); };
> class dir_it {
> // ...
> private:
> boost::shared_ptr<representation> m_rep;
> };
> ... and use a class derived from 'representation' in the implementation.
> However, this is rather inconvenient since I would have to cast the
> pointer whenever I want to access it, ie.
> static_cast<real_representation*>(m_rep)->m_member ...
> Now, what are the options to avoid this? I don't think that there is any
> using the type 'boost::shared_ptr'

There is no reason you should need to do this provided you have an
out-of-line definition for the destructor of dir_it. You should be able to
simply provide a forward declaration of the representation class. I do that
all the time

   class dir_it {
     class representation;
     boost::shared_ptr<representation> m_rep;


P.S. I'd much prefer abbreviation of "representation" to abbreviation of
"directory_iterator" ;)

Boost list run by bdawes at, gregod at, cpdaniel at, john at