(C++) Boost signal example 3: emitting two arguments and reading a result
February 24, 2017 · View on GitHub
(C++) Boost signal example 3: emitting two arguments and reading a result
This Boost signal example shows how to emit this.
Technical facts
Operating system(s) or programming environment(s)
Lubuntu 12.10 (quantal)
Qt Creator 2.5.2
- G++ 4.7.2
Libraries used:
STL: GNU ISO C++ Library, version
4.7.2
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 ); }