slot_arguments.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Example program for passing arguments from signal invocations to slots.
  2. //
  3. // Copyright Douglas Gregor 2001-2004.
  4. // Copyright Frank Mori Hess 2009.
  5. //
  6. // Use, modification and
  7. // distribution is subject to the Boost Software License, Version
  8. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. // For more information, see http://www.boost.org
  11. #include <iostream>
  12. #include <boost/signals2/signal.hpp>
  13. //[ slot_arguments_slot_defs_code_snippet
  14. void print_args(float x, float y)
  15. {
  16. std::cout << "The arguments are " << x << " and " << y << std::endl;
  17. }
  18. void print_sum(float x, float y)
  19. {
  20. std::cout << "The sum is " << x + y << std::endl;
  21. }
  22. void print_product(float x, float y)
  23. {
  24. std::cout << "The product is " << x * y << std::endl;
  25. }
  26. void print_difference(float x, float y)
  27. {
  28. std::cout << "The difference is " << x - y << std::endl;
  29. }
  30. void print_quotient(float x, float y)
  31. {
  32. std::cout << "The quotient is " << x / y << std::endl;
  33. }
  34. //]
  35. int main()
  36. {
  37. //[ slot_arguments_main_code_snippet
  38. boost::signals2::signal<void (float, float)> sig;
  39. sig.connect(&print_args);
  40. sig.connect(&print_sum);
  41. sig.connect(&print_product);
  42. sig.connect(&print_difference);
  43. sig.connect(&print_quotient);
  44. sig(5., 3.);
  45. //]
  46. return 0;
  47. }