Added link from postconstructor section of tutorial

to deconstruct example programs.  Added a warning about
binding a shared_ptr you intended to track to a slot.


[SVN r51141]
This commit is contained in:
Frank Mori Hess 2009-02-09 15:50:14 +00:00
parent b7def07b77
commit 0cfa23c8f9
2 changed files with 22 additions and 5 deletions

View File

@ -137,7 +137,7 @@
</section>
</section>
<section id="signals2.examples.deconstruct">
<title>Postconstructors and Predestructors with <functionname>deconstruct()</functionname></title>
<title>Postconstructors and Predestructors with <code>deconstruct()</code></title>
<section id="signals2.examples.deconstruct.postconstructor_ex1">
<title>postconstructor_ex1</title>
<para>

View File

@ -631,10 +631,22 @@ boost::shared_ptr&lt;NewsMessageArea&gt; newsMessageArea(new NewsMessageArea(/*
deliverNews.<methodname>connect</methodname>(signal_type::slot_type(&amp;NewsMessageArea::displayNews,
newsMessageArea.get(), _1).track(newsMessageArea));
</programlisting>
<para>Note there is no explicit call to bind() needed in the above example. If the
<classname alt="slotN">slot</classname> constructor is passed more than one
argument, it will automatically pass all the arguments to <code>bind</code> and use the
returned function object.</para>
<para>
Note there is no explicit call to bind() needed in the above example. If the
<classname alt="slotN">slot</classname> constructor is passed more than one
argument, it will automatically pass all the arguments to <code>bind</code> and use the
returned function object.
</para>
<para>Also note, we pass an ordinary pointer as the
second argument to the slot constructor, using <code>newsMessageArea.get()</code>
instead of passing the <code>shared_ptr</code> itself. If we had passed the
<code>newsMessageArea</code> itself, a copy of the <code>shared_ptr</code> would
have been bound into the slot function, preventing the <code>shared_ptr</code>
from expiring. However, the use of
<methodname alt="boost::signals2::slotN::track">slot::track</methodname>
implies we wish to allow the tracked object to expire, and automatically
disconnect the connection when this occurs.
</para>
</section>
<section id="signals2.tutorial.deconstruct">
@ -657,6 +669,11 @@ returned function object.</para>
through the <functionname>deconstruct()</functionname> function, and their
associated <code>adl_postconstruct()</code> function will always be called.
</para>
<para>The <link linkend="signals2.examples.deconstruct">examples</link> section
contains several examples of defining classes with postconstructors and
predestructors, and creating objects of these classes using
<functionname>deconstruct()</functionname>
</para>
<para>
Be aware that the postconstructor/predestructor support in Boost.Signals2
is in no way essential to the use of the library. The use of