hello_world_multi_slot.cpp 835 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Multiple slot 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_def_code_snippet
  13. struct Hello
  14. {
  15. void operator()() const
  16. {
  17. std::cout << "Hello";
  18. }
  19. };
  20. //]
  21. //[ world_def_code_snippet
  22. struct World
  23. {
  24. void operator()() const
  25. {
  26. std::cout << ", World!" << std::endl;
  27. }
  28. };
  29. //]
  30. int main()
  31. {
  32. //[ hello_world_multi_code_snippet
  33. boost::signals2::signal<void ()> sig;
  34. sig.connect(Hello());
  35. sig.connect(World());
  36. sig();
  37. //]
  38. return 0;
  39. }