Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Boost signal example 3: emitting two arguments and reading a result

 

This Boost signal example shows how to emit this.

 

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: CppBoostSignalExample3.pro

 

TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++ -Werror


 

 

 

 

 

main.cpp

 

#include <cassert>
#include <boost/function.hpp>

struct MyClass
{
  MyClass(const int x = 0) : m_x(x) {}
  int Plus( const int x) const { return m_x + x; }
  int Minus(const int x) const { return m_x - x; }
  int m_x;
};

int main()
{
  typedef boost::function<int(const MyClass*,int)> Function;
  MyClass c;
  Function f1 = &MyClass::Plus;
  Function f2 = &MyClass::Minus;
  assert( f1(&c,1000) ==  1000 );
  assert( f2(&c,1000) == -1000 );
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml