CPP/Boost/Signals/Class

From ProgrammingExamples

< CPP
Jump to: navigation, search

Class.cpp

#include <boost/signal.hpp>
#include <boost/bind.hpp>
 
#include <iostream>
 
class A
{
public:
  boost::signal<void ()> MySignal;
};
 
class B
{
public:
  void MySlot() {std::cout << "Slot called." << std::endl;}
};
 
int main()
{
  A a;
  B b;
 
  a.MySignal.connect(boost::bind(&B::MySlot, &b));
  a.MySignal();
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
Project(Class)
 
ADD_EXECUTABLE(Class Class.cpp)
TARGET_LINK_LIBRARIES(Class boost_signals-mt)
Personal tools