hello_world_slot.cpp 843 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Beginner hello world example for Boost.Signals2
  2. // Copyright Douglas Gregor 2001-2004.
  3. // Copyright Frank Mori Hess 2009.
  4. //
  5. // Use, modification and
  6. // distribution is subject to the Boost Software License, Version
  7. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. // For more information, see http://www.boost.org
  10. #include <iostream>
  11. #include <boost/signals2/signal.hpp>
  12. //[ hello_world_def_code_snippet
  13. struct HelloWorld
  14. {
  15. void operator()() const
  16. {
  17. std::cout << "Hello, World!" << std::endl;
  18. }
  19. };
  20. //]
  21. int main()
  22. {
  23. //[ hello_world_single_code_snippet
  24. // Signal with no arguments and a void return value
  25. boost::signals2::signal<void ()> sig;
  26. // Connect a HelloWorld slot
  27. HelloWorld hello;
  28. sig.connect(hello);
  29. // Call all of the slots
  30. sig();
  31. //]
  32. return 0;
  33. }