Boost logo

Boost :

From: Beman Dawes (beman_at_[hidden])
Date: 2000-08-29 20:15:15

Thomas Matelich wrote:

><whine> I wanna inherit shared_ptr </whine>
>Anyway, here's my situation, I'm writing a library for a simple plugin
>architecture. Objects can be created from classes in dynamic libraries
>dynamically. I want those objects to be shared_ptrs and be able to
>construct themselves. I think this qualifies as an isa relationship.
>In general, their only purpose is to be used like a shared_ptr.
>So, is shared_ptr always going to use private for share and have no
>virtual destructor, or is this matter up for discussion?

Let me see if I understand. Let's say your class Foo needs an int and a
double for constructor arguments. For the sake of discussion, so you were
just going to cut-and-paste. You copy shared_ptr, and change the name to
Foo. You replace the constructor from a pointer with a constructor from an
int and a double. Works fine. But Foo is going to be used as a
polymorphic base class, so you make the destructor virtual.

But you don't actually want to cut-and-paste. You want to just publicly
inherit shared_ptr<>. OK, that sounds like better software engineering;
reuse rather than reinvent.

So you would like the private member to be protected, so you can get at it
directly, and you would like the destructor to be virtual so destruction is

But do you really need to get at the private ptr member? Doesn't
shared_ptr provide public member functions for any access you need? And if
Foo's destructor is virtual, why does it matter if shared_ptr's isn't?

(I'm not entirely adverse to making ptr protected rather than private, but
I sure don't want to make the destructor virtual. But I'm not sure you
need either change to do what you want to do. OTOH, it's getting close to
my bedtime and I may be misunderstanding your problem.)



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