no_function.cpp

来自「C++的一个好库。。。现在很流行」· C++ 代码 · 共 45 行

CPP
45
字号
// Boost.Signals library

// Copyright Douglas Gregor 2001-2003. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// For more information, see http://www.boost.org

#include <iostream>
#include <boost/signals/signal2.hpp>
#include <string>
#include <functional>

void print_sum(int x, int y)
{
  std::cout << "Sum = " << x+y << std::endl;
}

void print_product(int x, int y)
{
  std::cout << "Product = " << x*y << std::endl;
}

void print_quotient(float x, float y)
{
  std::cout << "Quotient = " << x/y << std::endl;
}

int main()
{
  typedef boost::signal2<void, int, int, boost::last_value<void>,
                         std::string, std::less<std::string>,
                         void (*)(int, int)> sig_type;

  sig_type sig;
  sig.connect(&print_sum);
  sig.connect(&print_product);

  sig(3, 5); // print sum and product of 3 and 5

  // should fail
  //   sig.connect(&print_quotient);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?