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


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
hared_count::shared_count(Y*) [with Y = X]'
../../../boost/shared_ptr.hpp:173: instantiated from `boost::shared_ptr<
late-parameter-1-1> >::shared_ptr(Y*) [with Y = X, T = X]'
../../../boost/shared_ptr.hpp:394: instantiated from `void
<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 {
    class deleter;
    friend class deleter;
    class deleter {
        void operator()(X * p) { delete p; }
    static shared_ptr<X> create() {
        shared_ptr<X> px(new X, X::deleter());
        return px;

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

Vicente Juan Botet Escribá

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