C
crichmon
Hi,
I have a class that maintains a set of other objects. To save space, I'd
like to have a set of pointers to other objects, as multiple things can
reference/point to a unique object. The problem I've having though is that
I want the set to to use the object as the key, not the pointer. But it
gets trickier! I'm using a custom smart pointer instead of regular pointers
to allow poor-man's garbage collection.
My class kinda looks like
#include <set>
using namespace std;
class Foo
{
public:
typedef set<SmartPtr<Bar> > BarPtrSet;
typedef set<SmartPtr<Bar> >::iterator BPSiterator;
private:
BarPtrSet other_objects;
....
};
I tried a hack by making SmartPtr's less-than operator compare dereferenced
pointers rather than pointers, but that didn't really work and it causes
problems elsewhere in my code... and I am really hoping that I don't have to
just use set<Bar>.
My first thought is that I should modify the second template parameter of
set so that it is comparing something else, but I haven't found anything
that works yet... any thoughts out there?
thanks,
crichmon
I have a class that maintains a set of other objects. To save space, I'd
like to have a set of pointers to other objects, as multiple things can
reference/point to a unique object. The problem I've having though is that
I want the set to to use the object as the key, not the pointer. But it
gets trickier! I'm using a custom smart pointer instead of regular pointers
to allow poor-man's garbage collection.
My class kinda looks like
#include <set>
using namespace std;
class Foo
{
public:
typedef set<SmartPtr<Bar> > BarPtrSet;
typedef set<SmartPtr<Bar> >::iterator BPSiterator;
private:
BarPtrSet other_objects;
....
};
I tried a hack by making SmartPtr's less-than operator compare dereferenced
pointers rather than pointers, but that didn't really work and it causes
problems elsewhere in my code... and I am really hoping that I don't have to
just use set<Bar>.
My first thought is that I should modify the second template parameter of
set so that it is comparing something else, but I haven't found anything
that works yet... any thoughts out there?
thanks,
crichmon