|
Boost Users : |
From: Chuck Messenger (yg-boost-users_at_[hidden])
Date: 2003-05-16 08:58:40
Testing out the Boost signals lib, I wrote:
-----------
#include <boost/signal.hpp>
#include <iostream>
using namespace std;
using namespace boost;
struct X {
void operator()(int val) { cout << "X <- " << val << endl; }
X() { cout << "X constructor\n"; }
~X() { cout << "X destructor\n"; }
};
int main() {
{
cout << " phase 1\n";
signal<void (int)> sig;
cout << " phase 2\n";
X x;
cout << " phase 3\n";
sig.connect(x);
cout << " phase 4\n";
}
cout << " phase 5\n";
return 0;
}
-------------------
The following output is generated (gcc3.2.2 on Mandrake 9.1):
------------------------
phase 1
phase 2
X constructor
phase 3
X destructor
X destructor
X destructor
X destructor
X destructor
X destructor
X destructor
X destructor
phase 4
X destructor
X destructor
phase 5
------------------------
Why the multiple calls to X's destructor? I'd have expected just one.
It looks like the signals lib is misbehaving.
Can anyone offer an explanation?
- Chuck
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