Boost C++ Libraries: Ticket #12483: signals2 bind to member function by value fail to signal when using trackable https://svn.boost.org/trac10/ticket/12483 <p> In my trail to learn and get comfortable with signals2 I wrote a small test program. In this program I encountered what I believe to be inconsistency in the way that signals2 connect to member functions when using bind, when using trackable aswell. </p> <div class="wikipage" style="font-size: 80%"><p> Test program: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&quot;boost/signals2.hpp&quot;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="k">class</span> <span class="nc">SignalTest</span> <span class="o">:</span> <span class="k">public</span> <span class="n">boost</span><span class="o">::</span><span class="n">signals2</span><span class="o">::</span><span class="n">trackable</span> <span class="p">{</span> <span class="k">public</span><span class="o">:</span> <span class="n">SignalTest</span><span class="p">()</span> <span class="p">{};</span> <span class="kt">void</span> <span class="nf">printInfo</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">name</span><span class="p">,</span> <span class="kt">int</span> <span class="n">num</span><span class="p">)</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Signal: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">name</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">num</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="p">}</span> <span class="p">};</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="n">boost</span><span class="o">::</span><span class="n">signals2</span><span class="o">::</span><span class="n">signal</span><span class="o">&lt;</span><span class="kt">void</span> <span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span><span class="p">,</span> <span class="kt">int</span><span class="p">)</span><span class="o">&gt;</span> <span class="n">sig</span><span class="p">;</span> <span class="n">SignalTest</span> <span class="n">test1</span><span class="p">;</span> <span class="n">sig</span><span class="p">.</span><span class="n">connect</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">bind</span><span class="p">(</span><span class="o">&amp;</span><span class="n">SignalTest</span><span class="o">::</span><span class="n">printInfo</span><span class="p">,</span> <span class="n">test1</span><span class="p">,</span> <span class="n">_1</span><span class="p">,</span> <span class="n">_2</span><span class="p">));</span> <span class="n">sig</span><span class="p">(</span><span class="s">&quot;Test&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span> <span class="p">{</span> <span class="n">SignalTest</span> <span class="n">test2</span><span class="p">;</span> <span class="n">sig</span><span class="p">.</span><span class="n">connect</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">bind</span><span class="p">(</span><span class="o">&amp;</span><span class="n">SignalTest</span><span class="o">::</span><span class="n">printInfo</span><span class="p">,</span> <span class="n">test2</span><span class="p">,</span> <span class="n">_1</span><span class="p">,</span> <span class="n">_2</span><span class="p">));</span> <span class="n">sig</span><span class="p">(</span><span class="s">&quot;Test&quot;</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span> <span class="p">}</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div></div><p> The code above compiles and running it I'd expect both signals to be printed, however nothing is printed. If however I bind the signalTest object "test2" by reference like the code below: </p> <div class="wikipage" style="font-size: 80%"><p> Bind by reference: </p> <div class="wiki-code"><div class="code"><pre><span class="n">sig</span><span class="p">.</span><span class="n">connect</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">bind</span><span class="p">(</span><span class="o">&amp;</span><span class="n">SignalTest</span><span class="o">::</span><span class="n">printInfo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">test2</span><span class="p">,</span> <span class="n">_1</span><span class="p">,</span> <span class="n">_2</span><span class="p">));</span> </pre></div></div></div><p> The following is printed: </p> <div class="wikipage" style="font-size: 80%"><p> test2 bind by reference print </p> <div class="wiki-code"><div class="code"><pre>Signal: Test 2 </pre></div></div></div><p> And if I also bind signalTest object "test1" by reference the following is printed: </p> <div class="wikipage" style="font-size: 80%"><p> test1 and test2 bind by reference print </p> <div class="wiki-code"><div class="code"><pre>Signal: Test 1 Signal: Test 2 Signal: Test 2 </pre></div></div></div><p> As I was lead to understand from the example code of section "Automatic Connection Management" in the tutorial at <a href="http://www.boost.org/doc/libs/1_61_0/doc/html/signals2/tutorial.html#idp394616720">http://www.boost.org/doc/libs/1_61_0/doc/html/signals2/tutorial.html#idp394616720</a> I should be able to call the member function by value, however this is not the case using trackable. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12483 Trac 1.4.3 kim.lykke.johansen@… Mon, 26 Sep 2016 13:05:27 GMT attachment set https://svn.boost.org/trac10/ticket/12483 https://svn.boost.org/trac10/ticket/12483 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">signals.cpp</span> </li> </ul> Ticket kim.lykke.johansen@… Mon, 26 Sep 2016 13:05:55 GMT attachment set https://svn.boost.org/trac10/ticket/12483 https://svn.boost.org/trac10/ticket/12483 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">makefile</span> </li> </ul> Ticket