1 | #include <iostream>
|
---|
2 | #include <string>
|
---|
3 | #include <boost/signal.hpp>
|
---|
4 | #include <boost/bind.hpp>
|
---|
5 |
|
---|
6 | typedef boost::signal<void ()> MySignal;
|
---|
7 |
|
---|
8 | class Test : public boost::signals::trackable {
|
---|
9 | public:
|
---|
10 | Test(const std::string &s, MySignal & sgn);
|
---|
11 | void mySlot();
|
---|
12 | private:
|
---|
13 | std::string str;
|
---|
14 | };
|
---|
15 |
|
---|
16 | Test::Test(const std::string &s, MySignal & sgn) {
|
---|
17 | str = s;
|
---|
18 | sgn.connect(boost::bind(&Test::mySlot, this));
|
---|
19 | }
|
---|
20 |
|
---|
21 | void Test::mySlot() {
|
---|
22 | std::cerr << str << std::endl;
|
---|
23 | }
|
---|
24 |
|
---|
25 | int main() {
|
---|
26 | MySignal mySgn;
|
---|
27 | std::cerr << "create A" << std::endl;
|
---|
28 | Test *A = new Test("A", mySgn);
|
---|
29 | std::cerr << "fire SGN" << std::endl;
|
---|
30 | mySgn();
|
---|
31 | std::cerr << "create B" << std::endl;
|
---|
32 | Test *B = new Test("B", mySgn);
|
---|
33 | std::cerr << "fire SGN" << std::endl;
|
---|
34 | mySgn();
|
---|
35 | std::cerr << "delete A" << std::endl;
|
---|
36 | delete A;
|
---|
37 | std::cerr << "fire SGN" << std::endl;
|
---|
38 | mySgn();
|
---|
39 | std::cerr << "delete B" << std::endl;
|
---|
40 | delete B;
|
---|
41 | std::cerr << "fire SGN" << std::endl;
|
---|
42 | mySgn();
|
---|
43 |
|
---|
44 | std::cerr << "exit" << std::endl;
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 |
|
---|