newbie: shared_ptr member function customer deleter???

Hello:
I just started using some boost today. I am trying to use a non-static
member function as the deleter in a shared_ptr. I was looking at the
source code and I don't think it is supported. This is what I had:
shared_ptr<Environment> environment(Environment::createEnvironment(),
Environment::terminateEnvironment);
string userName = "monkey_bottoms";
string password = "blahblahblah"
shared_ptr<Connection> connection(
environment->createConnection(
userName,
password),
&Environment::terminateConnection);
This didn't work at all! When I looked at the source I saw why. Note
that Environment::terminateConnection is a static method. However,
this source works fine for the static Environment::createEnvironment
method.
I am working in Visual Studio 8 with the OCCI. For the time being, I
have made a temporary solution. I am hoping someone can help me find a
less customized solution. Plus, I am thinking having a pointer to an
object that I am trying to manage kind of defeats the point. Here you
go:
#include "occi.h"
#include

Travis Parks wrote:
Use boost::bind( &Environment::terminateConnection, environment, _1 ) as a deleter. If for some reason you don't want connections to keep a shared_ptr to the environment and prevent its deletion, you can use boost::bind( &Environment::terminateConnection, environment.get(), _1 ).
participants (2)
-
Peter Dimov
-
Travis Parks