<html><body bgcolor="#ffffff"><font face="Verdana" size="1">Hi all,<br><br>Sorry in the first letter the creation of shared pointer was wrong. Thanks Scott to point it out.<br>All the two test programs can run to the end and can return correct result. The only difference between them was at the end of second program an exception was thrown out.<br>Thanks again.<br><br>I come across a strange exception when I am using boost shared pointer with omniORB.<br>I
am trying to wrap the CORBA operations (creating orb, resolving remote
object) into a class then my coleagues can use it without knowing any
thing about CORBA.<br>The interface of remote object is like this:<br>interface IA<br>{<br> void fa();<br> void fb();<br>}<br><br>The C++ class I defined is like this:<br>class CA<br>{<br> public:<br><br> CA();<br> ~CA();<br> void fa();<br> void fb();<br> <br> private: <br> CORBA::ORB_var m_orb;<br>};<br><br>All
the CORBA related operations (creating orb, finding NameService,
creating reference of remote object) have been encapsulated into the
constructor CA::CA().<br>In the destructor CA::~CA() I shutdown the orb. It is like this: { m_orb->shutdown(true); m_orb->destroy(); }<br><br>Then I have two test program all use boost shared pointer and one can work well one can not.<br>The one can work well:<br><br>int main(int argc, char** argv)<br>{<br> {<br> CA ca();<br> ca.fa();<br> ca.fb();<br> }<br> <br> {<br> Ca* pa= new CA();<br> pa->fa();<br> pa->fb();<br> delete pa;<br> }<br> <br> {<br> </font><font face="Verdana" size="1">shared_ptr<CA> sa(new CA);</font><br><font face="Verdana" size="1"> sa->fa();<br> sa->fb();<br> }<br> <br>}<br><br>The one can not work well:<br><br>int main(int argc, char** argv)<br>{<br> <br> CA ca();<br> ca.fa();<br> ca.fb();<br> <br> <br> Ca* pa= new CA();<br> pa->fa();<br> pa->fb();<br> delete pa;<br> <br> <br> {<br> </font><font face="Verdana" size="1">shared_ptr<CA> sa(new CA);</font><br><font face="Verdana" size="1"> sa->fa();<br> sa->fb();<br> }<br> <br>}<br>The omniORB reports this:<br>omniORB: throw OBJECT_NOT_EXIST from corbaOrb.cc:842 (NO,OBJECT_NOT_EXIST_NoMatch)<br>terminate called after throwing an instance of 'CORBA::OBJECT_NOT_EXIST'<br><br>It
looks like when I am using shared_ptr the shared pointer and omniORB
all try to delete someone so they conflict with each other. But how?
Why the first program can work well but the second would throw out
exception all the time?<br><br>Thanks a lot for your help.<br><br>Regards</font><br>
<br></body></html>