title: Boost Signals2 tracking
body: <p>I am using Boost Signals2 in one of our project.In this I want automatic connection management,for this I am testing Boost Signals2 tracking but I am not getting slot invoked.
  After I run following code , slots are not called . 
  Environment:
  VS 2010,windows 7,boost 1.54</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;iostream&gt;
      #include &lt;string&gt;
      #include &lt;boost/bind.hpp&gt;
      #include &lt;boost/enable_shared_from_this.hpp&gt;
      #include &lt;boost/signals2/signal.hpp&gt;
      #include &lt;boost/shared_ptr.hpp&gt;
  
  
      typedef boost::signals2::signal&lt;void ()&gt;  signal_test;
      using namespace boost;
  
      class SubjectTest
      {
  
      public:
          void Connect(const signal_test::slot_type &amp;subscriber)
          {
              m_Signal.connect(subscriber);
              std::cout &lt;&lt; "No of connections : " &lt;&lt; m_Signal.num_slots() &lt;&lt; std::endl;
          }
          void Notify()
          {
              m_Signal();
          }
      private:
          signal_test m_Signal;
      };
  
      class Listner 
      {
      public:
          Listner(){}
          ~Listner(){}
          Listner(std::string name)
          :m_name(name)
          {
          }
          void GotSignal()
          {
              std::cout &lt;&lt; m_name &lt;&lt;  std::endl;
          }
          void ConnectWithTracking(SubjectTest *s)
          {
              shared_ptr&lt;Listner&gt; l = new Listner();
              s-&gt;Connect(signal_test::slot_type(&amp;Listner::GotSignal,l.get()).track(l));
  
          }
          void ConnectNormal(SubjectTest *s)
          {
              s-&gt;Connect(bind(&amp;Listner::GotSignal,this));
  
          }
  
      private:
          std::string m_name;
          shared_ptr&lt;Listner&gt; l;
      };
  
      void main()
      {
          Listner l2("First"); 
          SubjectTest sub;
  
          try
          {
          l2.ConnectWithTracking(&amp;sub);
          //l2.ConnectNormal(&amp;sub);
          sub.Notify();
  
          {
              Listner l3("Second"); 
  
              l3.ConnectWithTracking(&amp;sub);
              //l3.ConnectNormal(&amp;sub);
              sub.Notify();
          }
  
          sub.Notify();
          }
          catch(std::exception ex)
          {
              std::cout &lt;&lt; ex.what() &lt;&lt; std::endl;
          }
  
          std::cout &lt;&lt; "Finish" &lt;&lt;std::endl;
      }
  </code></pre>
  
  <p><strong>Updated :</strong>
  *<em>Working now</em>*</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;iostream&gt;
      #include &lt;string&gt;
      #include &lt;boost/bind.hpp&gt;
      #include &lt;boost/enable_shared_from_this.hpp&gt;
      #include &lt;boost/signals2/signal.hpp&gt;
      #include &lt;boost/shared_ptr.hpp&gt;
  
  
      typedef boost::signals2::signal&lt;void ()&gt;  signal_test;
      using namespace boost;
  
      class SubjectTest
      {
  
      public:
          void Connect(const signal_test::slot_type &amp;subscriber)
          {
              m_Signal.connect(subscriber);
              std::cout &lt;&lt; "No of connections : " &lt;&lt; m_Signal.num_slots() &lt;&lt; std::endl;
          }
          void Notify()
          {
              m_Signal();
          }
      private:
          signal_test m_Signal;
      };
  
      class Listner : public boost::enable_shared_from_this&lt;Listner&gt;
      {
      public:
          Listner(){}
          ~Listner(){}
          Listner(std::string name)
          :m_name(name)
          {
          }
          void GotSignal()
          {
              std::cout &lt;&lt; m_name &lt;&lt;  std::endl;
          }
          void ConnectWithTracking(SubjectTest *s)
          {
              s-&gt;Connect(signal_test::slot_type(&amp;Listner::GotSignal,shared_from_this().get()).track(shared_from_this()));
          }
          void ConnectNormal(SubjectTest *s)
          {
              s-&gt;Connect(bind(&amp;Listner::GotSignal,this));
          }
  
      private:
          std::string m_name;
  
      };
  
      void main()
      {
          shared_ptr&lt;Listner&gt; l2(new Listner("First")); 
  
          SubjectTest sub;
  
          try
          {
          l2-&gt;ConnectWithTracking(&amp;sub);
  
          sub.Notify();
  
          {
              shared_ptr&lt;Listner&gt; l3(new Listner("Second")); 
  
              l3-&gt;ConnectWithTracking(&amp;sub);
              //l3.ConnectNormal(&amp;sub);
              sub.Notify();
          }
  
          sub.Notify();
          }
          catch(std::exception ex)
          {
              std::cout &lt;&lt; ex.what() &lt;&lt; std::endl;
          }
  
          std::cout &lt;&lt; "Finish" &lt;&lt;std::endl;
      }
  </code></pre>
  
  <p>Now this is complete example of Signal2 Automatic Connection Management</p>