Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) BoostSignals2Example3

 

BoostQt CreatorLubuntu

 

Boost.Signals2 example 3 is a Boost.Signals2 example.

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppBoostSignals2Example3/CppBoostSignals2Example3.pro

 

include(../../ConsoleApplication.pri)
include(../../Libraries/Boost.pri)
SOURCES += main.cpp

 

 

 

 

 

./CppBoostSignals2Example3/main.cpp

 

#include <iostream>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <boost/bind.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/signals2.hpp>
#pragma GCC diagnostic pop

//NoIdea is a class that can ask for an answer, but
//has no idea what this answer is. It relies on a
//Boost.Units2 signal its return value
struct NoIdea
{
  NoIdea() : m_signal{} {}
  void Ask()
  {
    if (m_signal())
    {
      std::cout << *m_signal() << '\n';
    }
    else
    {
      std::cout << "[No one answers]" << '\n';
    }
  }
  boost::signals2::signal<std::string()> m_signal;
};

const std::string SayX() { return "The answer"; }

int main()
{
  NoIdea x;
  x.Ask();
  x.m_signal.connect(&SayX);
  x.Ask();
}

 

 

 

 

 

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