-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample2.cpp
More file actions
48 lines (37 loc) · 1.05 KB
/
example2.cpp
File metadata and controls
48 lines (37 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <sigc++/sigc++.h>
#include <string>
#include <iostream>
class Transmitter {
protected:
std::string m_origin; // parameter being sent to the slot
sigc::signal<void, const std::string &> m_slot; // slot container that takes a const std::string reference
public:
Transmitter(const std::string origin) : m_origin(origin) {}
sigc::signal<void, const std::string &> &getSlot() { return m_slot; }
void run(void);
};
void
Transmitter::run(void)
{
sleep(2);
m_slot.emit(m_origin); // Emit the signal
}
class Receiver {
public:
Receiver() {}
void get_message(const std::string &message);
};
void
Receiver::get_message(const std::string &message)
{
std::cout << "Got the message: " << message << std::endl;
}
int main()
{
Transmitter transmit("This is the message");
Receiver receipt;
// connect the member function get_message to the transmission slot
transmit.getSlot().connect( sigc::mem_fun(receipt, &Receiver::get_message) );
transmit.run();
return 0;
}