Consider I have the following struct
:
struct IDirect3D
{
IDirect3D() : ref_count_(0) {}
unsigned long Release() { return --ref_count_; }
private:
long ref_count_;
~IDirect3D() {}
};
I want to use shared_ptr
to it like in the followed code (minimal example):
int main()
{
boost::shared_ptr<IDirect3D> ptr;
IDirect3D* p = 0; // initialized somewhere
ptr.reset( p, boost::mem_fn( &IDirect3D::Release ) );
return 0;
}
This works OK in most cases, but crases if p
in equal to 0
. I have the following deleter which I want to use:
template<typename T, typename D>
inline void SafeDeleter( T*& p, D d )
{
if ( p != NULL ) {
(p->*d)();
p = NULL;
}
}
But the following code gives a lot of error (looks like it dumps the whole bind.hpp
):
ptr.reset( p, boost::bind( SafeDeleter, _1, &IDirect3D::Release ) );
What's wrong with my using of bind
?