[odb-users] Weak pointer can't be converted to shared pointer

Wayne Hackle hacklew at hotmail.com
Fri Apr 20 05:26:21 EDT 2012


Dear Boris and all,
I used "vector<weak_ptr<reply> >" to store a "reply" object and I am now having problem using the weak pointers.
Code as follows:
       string strReplies;	typedef vector<weak_ptr<reply> > reply_type;	reply_type vec_reply = msg.replies();	for (reply_type::iterator i(vec_reply.begin()); i != vec_reply.end(); i++)	{		weak_ptr<reply> wp_rep(*i);		shared_ptr<reply> sp_rep = i->lock();				strReplies.append(sp_rep->content());	}
debug shows the shared_ptr<reply> sp_rep address is void (all 0x000000).
I am almost sure it's something dead simple but I just can't find out what it is. All my searches failed me.
Before using weak_ptr, I used lazy_weak_ptr and it worked, but it has to be used with in a transaction (otherwise an out_of_transaction is thrown), which is a bit ugly or out of place.
Could somebody help please, appreciate it!
Hackle 		 	   		  


More information about the odb-users mailing list