summaryrefslogtreecommitdiff
path: root/examples/member_method.cc
blob: 2b4d732c9c7352cd07f3d88a1a3f321901b5cabf (plain)
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
/* Copyright 2003, The libsigc++ Development Team
 *
 *  Assigned to the public domain.  Use as you wish without
 *  restriction.
 */

#include <iostream>
#include <string>

#include <sigc++/sigc++.h>

class Something : public sigc::trackable
{
public:
  Something();

protected:

  virtual void on_print(int a);
  
  typedef sigc::signal<void, int> type_signal_print;
  type_signal_print signal_print;
    
};

Something::Something()
{
  auto iter = signal_print.connect( sigc::mem_fun(*this, &Something::on_print) );

  signal_print.emit(2);

  //This isn't necessary - it's just to demonstrate how to disconnect:
  iter->disconnect();
  signal_print.emit(3); //Prove that it is no longer connected.
}

void Something::on_print(int a)
{
  std::cout << "on_print recieved: " << a << std::endl;
}

int main()
{
  Something something;  
  return 0;
}