Ticket #852: test-gcc-boost.cc

File test-gcc-boost.cc, 968 bytes (added by Daryle Walker, 15 years ago)

Sample file copied from the SourceForge version of this ticket

Line 
1#include <iostream>
2#include <string>
3#include <boost/signal.hpp>
4#include <boost/bind.hpp>
5
6typedef boost::signal<void ()> MySignal;
7
8class Test : public boost::signals::trackable {
9public:
10 Test(const std::string &s, MySignal & sgn);
11 void mySlot();
12private:
13 std::string str;
14};
15
16Test::Test(const std::string &s, MySignal & sgn) {
17 str = s;
18 sgn.connect(boost::bind(&Test::mySlot, this));
19}
20
21void Test::mySlot() {
22 std::cerr << str << std::endl;
23}
24
25int 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