Boost logo

Boost :

Subject: [boost] [smart_ptr] shared_ptr<T> T destructor required even if a deleter function is provided
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-09-28 11:50:06


Hello,

I have compiled the example Preventing delete px.get()and every thing is OK
until we use the reset function because shared_ptr<X> request that the
destructor of X must be public even if a deleter function is provided. I'm
wondering if this is a BUG on the smart pointer library

Next follows the trace:

../../../boost/checked_delete.hpp: In function `void
boost::checked_delete(T*) [
with T = X]':
../../../boost/detail/shared_count.hpp:91: instantiated from
`boost::detail::s
hared_count::shared_count(Y*) [with Y = X]'
../../../boost/shared_ptr.hpp:173: instantiated from `boost::shared_ptr<
<temp
late-parameter-1-1> >::shared_ptr(Y*) [with Y = X, T = X]'
../../../boost/shared_ptr.hpp:394: instantiated from `void
boost::shared_ptr<
<template-parameter-1-1> >::reset(Y*) [with Y = X, T = X]'
test_shared_ptr.cpp:37: instantiated from here
test_shared_ptr.cpp:13: error: `X::~X()' is private
../../../boost/checked_delete.hpp:34: error: within this context

And here it is the source code

#include <boost/shared_ptr.hpp>
using namespace boost;
class X {
private:
    ~X(){};
    class deleter;
    friend class deleter;
    class deleter {
    public:
        void operator()(X * p) { delete p; }
    };
public:
    static shared_ptr<X> create() {
        shared_ptr<X> px(new X, X::deleter());
        return px;
    }
};

int main () {
    shared_ptr<X> ptr = X::create();
    ptr.reset(X::create().get());
    return 0;
}

______________________
Vicente Juan Botet Escribá


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