<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>&nbsp;&nbsp; &nbsp;void fa();<br>&nbsp;&nbsp; &nbsp;void fb();<br>}<br><br>The C++ class I defined is like this:<br>class CA<br>{<br>&nbsp;&nbsp; &nbsp;public:<br><br>&nbsp;&nbsp; &nbsp;CA();<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;~CA();<br>&nbsp;&nbsp; &nbsp;void fa();<br>&nbsp;&nbsp; &nbsp;void fb();<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp; &nbsp;private:&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp; &nbsp;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-&gt;shutdown(true); m_orb-&gt;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>&nbsp;&nbsp; &nbsp;{<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;CA ca();<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ca.fa();<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ca.fb();<br>&nbsp;&nbsp; &nbsp;}<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp; &nbsp;{<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Ca* pa= new CA();<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;pa-&gt;fa();<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;pa-&gt;fb();<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;delete pa;<br>&nbsp;&nbsp; &nbsp;}<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp; &nbsp;{<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; </font><font face="Verdana" size="1">shared_ptr&lt;CA&gt; sa(new CA);</font><br><font face="Verdana" size="1">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sa-&gt;fa();<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sa-&gt;fb();<br>&nbsp;&nbsp; &nbsp;}<br>&nbsp;&nbsp; &nbsp;<br>}<br><br>The one can not work well:<br><br>int main(int argc, char** argv)<br>{<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp; &nbsp;CA ca();<br>&nbsp;&nbsp; &nbsp;ca.fa();<br>&nbsp;&nbsp; &nbsp;ca.fb();<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp; &nbsp;Ca* pa= new CA();<br>&nbsp;&nbsp; &nbsp;pa-&gt;fa();<br>&nbsp;&nbsp; &nbsp;pa-&gt;fb();<br>&nbsp;&nbsp; &nbsp;delete pa;<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp; &nbsp;{<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; </font><font face="Verdana" size="1">shared_ptr&lt;CA&gt; sa(new CA);</font><br><font face="Verdana" size="1">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sa-&gt;fa();<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sa-&gt;fb();<br>&nbsp;&nbsp; &nbsp;}<br>&nbsp;&nbsp; &nbsp;<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>