You are right.Thank you.<br><br><div class="gmail_quote">2012/12/23 Jaedyn K. Draper <span dir="ltr"><<a href="mailto:jaedyn.cppsig@jaedyn.co" target="_blank">jaedyn.cppsig@jaedyn.co</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    If you pass it to a function like that, it passes it by value even
    if it's a pointer. So it's calling the copy constructor (which you
    haven't defined so it isn't printing "A start"), rather than the
    regular constructor, and then destructing it.<br>
    <br>
    To pass an actual pointer rather than sending it by value, you need
    to do it like this:<br>
    <br>
    <pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px">
<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif"><div class="im">
<span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">    B</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">()</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span>{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> aa</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">new</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> A</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span><span>
    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">~</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">B</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">()</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">delete</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> 

aa</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">void</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> run</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">object ct</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">)</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transp arent">
        _obj</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">ct</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">();</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">              </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">//creat a python object</span></div>
<span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
        _obj</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">attr</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"fun1"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">)(ptr(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">aa</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">));</span><span>  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">//call a function named "fun1" with a pointer arg</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
        _obj</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">attr</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"fun2"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">)(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">ptr(aa</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">));</span><span>  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">//call a function named "fun2" with a pointer arg </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    A </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">*</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">aa</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    object _obj</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span></code></pre>
    <br>
    Note that both "aa" objects are wrapped by a call to "ptr()"<br>
    <br>
    Just be careful with the python when doing this, as it can cause a
    crash if python tries to access that object after its C++ lifetime
    has ended. So always make sure the python object's lifetime ends
    before the C++ object's does.<div><div class="h5"><br>
    <br>
    <div>On 12/22/2012 4:45 PM, simon zhang
      wrote:<br>
    </div>
    </div></div><blockquote type="cite"><div><div class="h5"><span>when

        I call python's function with pointer as an argument in
        boost.python, there are some troubles in destructor. The
        following is a sample code</span>
      <div> <span><br>
        </span></div>
      <div>
        <pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px">
<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif"><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">#include</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span><boost/python.hpp></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">#include</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"><boost/python/module.hpp></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">#include</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"><boost/python/def.hpp></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">#include</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"><string></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">#include</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"><iostream></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">using</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">namespace</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> boost</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">::</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">python</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">class</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> A </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">public</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">:</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    A</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">()</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
        std</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">::</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">cout</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><<</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"A start"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><<</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">std</span><span>::</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">endl</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">~</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">A</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">()</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">std</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">::</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">cout</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><<</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"A end"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><<</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">std</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">::</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">endl<u></u>;}</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">class</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> B </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">public</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">:</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    B</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">()</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> aa</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">new</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> A</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">~</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">B</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">()</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">delete</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> 

aa</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">void</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> run</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">object ct</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">)</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transp arent">
        _obj</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">ct</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">();</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">              </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">//creat a python object</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
        _obj</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">attr</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"fun1"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">)(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">aa</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:t ransparent">  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">//call a function named "fun1" with a pointer arg</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
        _obj</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">attr</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"fun2"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">)(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">aa</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:t ransparent">  </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">//call a function named "fun2" with a pointer arg </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    A </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">*</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">aa</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    object _obj</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">

BOOST_PYTHON_MODULE</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">ctopy</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">)</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">{</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    class_</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">A</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"A"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transp arent">init</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><>())</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    class_</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)"><b></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"B"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">init</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><>())</span><span>
    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">def</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"run"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,&</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">B</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">::</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transpar ent">run</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">)</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">}</span></code></pre>
      </div>
      <div><span><br>
        </span></div>
      <div><span>python:</span></div>
      <div>
        <pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px">
<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif"><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">import</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> ctopy
</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">class</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> tc</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">:</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    def fun1</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">self</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">tt</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">):</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
        print </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"fun1"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
    def fun2</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">self</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">tt</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">):</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
        print </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"fun2"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
bb</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">=</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">ctopy</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">D</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">()</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">
bb</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">run</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">tc</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">)</span></code></pre>

      </div>
      <div><span>this

          result:</span></div>
      <div>
        <pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px">
<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif"><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">A start
fun1
A end
fun2
A end
A end</span></code></pre>
      </div>
      <div>
        <h1>
          note:</h1>
        <p> The "A end"
          has been printed three.I try it in "valgrind"£¬there are some
          errors.I just want to run the destructor once.How to do?</p>
      </div>
      <div><br>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      </div></div><pre>_______________________________________________
Cplusplus-sig mailing list
<a href="mailto:Cplusplus-sig@python.org" target="_blank">Cplusplus-sig@python.org</a>
<a href="http://mail.python.org/mailman/listinfo/cplusplus-sig" target="_blank">http://mail.python.org/mailman/listinfo/cplusplus-sig</a></pre>
    </blockquote>
    <br>
  </div>

<br>_______________________________________________<br>
Cplusplus-sig mailing list<br>
<a href="mailto:Cplusplus-sig@python.org">Cplusplus-sig@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/cplusplus-sig" target="_blank">http://mail.python.org/mailman/listinfo/cplusplus-sig</a><br></blockquote></div><br>