R
ralpe
Hi,
I have a question regarding boost::shared_ptr. I want to let
shared_ptr take care of my objects' lifetimes, so I change
all my function signatures so that they accept shared_ptrs
instead of raw pointers.
I wonder how to deal with cases where a this pointer is
passed as an argument. Is it ok to write something like the
following?
void foo::bar()
{
add_to_collection(boost::shared_ptr<foo>(this));
}
int main()
{
boost::shared_ptr<foo> f(new foo());
foo->bar();
}
I'm asking because shared_ptr is non-intrusive and I fear
that the above code could create a second counter for an
object that is already reference counted.
Any comments?
I have a question regarding boost::shared_ptr. I want to let
shared_ptr take care of my objects' lifetimes, so I change
all my function signatures so that they accept shared_ptrs
instead of raw pointers.
I wonder how to deal with cases where a this pointer is
passed as an argument. Is it ok to write something like the
following?
void foo::bar()
{
add_to_collection(boost::shared_ptr<foo>(this));
}
int main()
{
boost::shared_ptr<foo> f(new foo());
foo->bar();
}
I'm asking because shared_ptr is non-intrusive and I fear
that the above code could create a second counter for an
object that is already reference counted.
Any comments?