D
Dave Rahardja
I need to design a container that must hold a set of references to a variety
of object types, managed by different memory managers. At some time, the
container must destroy each object. Currently I have the following design in
mind:
class Destructible // interface
{
public:
virtual void destroy() = 0;
};
class Container
{
public:
// ...
void add(Destructible& item);
// ...
void destroy();
};
void Container::destroy()
{
// ... iterate ...
items.destroy();
}
// An item in the container
class Item: virtual public Destructible
{
public:
virtual void destroy();
};
void Item::destroy()
{
MyMemoryManager::Lock lock(this);
~Item();
}
Is there an easier way to do this? Is there a way to make the container work
with objects without a custom destructor?
-dr
of object types, managed by different memory managers. At some time, the
container must destroy each object. Currently I have the following design in
mind:
class Destructible // interface
{
public:
virtual void destroy() = 0;
};
class Container
{
public:
// ...
void add(Destructible& item);
// ...
void destroy();
};
void Container::destroy()
{
// ... iterate ...
items.destroy();
}
// An item in the container
class Item: virtual public Destructible
{
public:
virtual void destroy();
};
void Item::destroy()
{
MyMemoryManager::Lock lock(this);
~Item();
}
Is there an easier way to do this? Is there a way to make the container work
with objects without a custom destructor?
-dr