Opened 2 years ago

#12483 new Support Requests

signals2 bind to member function by value fail to signal when using trackable

Reported by: kim.lykke.johansen@… Owned by: Douglas Gregor
Milestone: To Be Determined Component: signals
Version: Boost 1.61.0 Severity: Not Applicable
Keywords: signals2 trackable bind Cc:

Description

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.

Test program:

#include "boost/signals2.hpp"
#include <iostream>


class SignalTest : public boost::signals2::trackable
{
public:
        SignalTest() {};

        void printInfo(const std::string name, int num)
        {
                std::cout << "Signal: " << name << " " << num << std::endl;
        }
};

int main()
{
        boost::signals2::signal<void (const std::string&, int)> sig;

        SignalTest test1;
        sig.connect(boost::bind(&SignalTest::printInfo, test1, _1, _2));
        sig("Test", 1);

        {
                SignalTest test2;
                sig.connect(boost::bind(&SignalTest::printInfo, test2, _1, _2));
                sig("Test", 2);
        }

        return 0;
}

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:

Bind by reference:

sig.connect(boost::bind(&SignalTest::printInfo, &test2, _1, _2));

The following is printed:

test2 bind by reference print

Signal: Test 2

And if I also bind signalTest object "test1" by reference the following is printed:

test1 and test2 bind by reference print

Signal: Test 1
Signal: Test 2
Signal: Test 2

As I was lead to understand from the example code of section "Automatic Connection Management" in the tutorial at http://www.boost.org/doc/libs/1_61_0/doc/html/signals2/tutorial.html#idp394616720 I should be able to call the member function by value, however this is not the case using trackable.

Attachments (2)

signals.cpp (769 bytes) - added by kim.lykke.johansen@… 2 years ago.
makefile (245 bytes) - added by kim.lykke.johansen@… 2 years ago.

Download all attachments as: .zip

Change History (2)

Changed 2 years ago by kim.lykke.johansen@…

Attachment: signals.cpp added

Changed 2 years ago by kim.lykke.johansen@…

Attachment: makefile added
Note: See TracTickets for help on using tickets.