Boost logo

Boost Users :

Subject: [Boost-users] Beginner question: Why boost::signal creates another instance of the slot object ?
From: Mauricio Gomes (mgpensar_at_[hidden])
Date: 2010-08-19 18:02:23


Hi,

I am running the program below (Vista with boost 1.43, mingw/gcc 4.5.1).

I would expect slot.x to be 5 but it is zero.

Why boost::signal creates another instance of the slot object ?
What am I missing here ?

Thank you in advance for your attention,
Mau.

----------------------------------------------------------------
#include <iostream>
#include <boost/signal.hpp>

struct S
{
    int x;

    S (): x(0) {}

    void operator () (int i)
    {
        std::cout << "&slot1 = " << this << std::endl;
        x = i;
        std::cout << "slot1.x = " << this->x << std::endl;
    }
};

int main ()
{
    S slot;
    boost::signal<void (int)> sig;
    std::cout << "&slot2 = " << &slot << std::endl;

    sig.connect (slot);
    sig (5);

    std::cout << "slot2.x = " << slot.x << std::endl;
    return 0;
}
--------------------------------------------------------------------
Output:
&slot2 = 0x22fee4
&slot1 = 0x341448
slot1.x = 5
slot2.x = 0


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net