Boost logo

Boost :

From: Neal D. Becker (nbecker_at_[hidden])
Date: 2002-09-18 08:59:36


I notice an unexpected difference between ptr, auto_ptr, and
shared_ptr:

#include <memory>
#include <boost/shared_ptr.hpp>
#include <iostream>

typedef std::iostream X;

struct Options {
  X* x;
  std::auto_ptr<X> y;
  boost::shared_ptr<X> z;
  Options() :
    x(0),
    y(0),
    z(0)
  {}
};

g++3 -c bug.cc -I /usr/local/src/boost
bug.cc: In constructor `Options::Options()':
bug.cc:15: no matching function for call to `boost::shared_ptr<X>::shared_ptr(
   int)'
/usr/local/src/boost/boost/shared_ptr.hpp:74: candidates are:
   boost::shared_ptr<X>::shared_ptr(const boost::shared_ptr<X>&)
/usr/local/src/boost/boost/shared_ptr.hpp:85:
   boost::shared_ptr<T>::shared_ptr() [with T = X]

The initialization of plain ptr with "0" is OK, and so is auto_ptr,
but not shared_ptr. Why? Is this a defect?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk