I'm using lower_bound() for searching in sorted vector of weak_ptr
vector<weak_ptr<A> >::iterator findA( const string & id ) const
{
sa = make_shared<A>( id );
a = sa;
return lower_bound( owners.begin(), owners.end(), sa,
[] ( const weak_ptr<A> & l, const weak_ptr<A> & r )
{
return (l.lock()->getID() < r.lock()->getID());
} );
}
Where sa
is a shared_ptr<A>
, class A
has got a private string ID
and a public method getID
.
When findA
calls getID
it causes segfault. I guess it's because of lock()
, which retruns empty shared_ptr
.
How can I fix it?