更多信息如果您在boost::signals
库望去,你会看到一个例子很不错的,这是非常优雅:
假设你有4种功能,如:
void print_sum(float x, float y)
{
std::cout << "The sum is " << x+y << std::endl;
}
void print_product(float x, float y)
{
std::cout << "The product is " << x*y << std::endl;
}
void print_difference(float x, float y)
{
std::cout << "The difference is " << x-y << std::endl;
}
void print_quotient(float x, float y)
{
std::cout << "The quotient is " << x/y << std::endl;
}
然后,如果你想叫他们一个优雅的方式尝试:
boost::signal<void (float, float)> sig;
sig.connect(&print_sum);
sig.connect(&print_product);
sig.connect(&print_difference);
sig.connect(&print_quotient);
sig(5, 3);
,输出是:
The sum is 8
The product is 15
The difference is 2
The quotient is 1.66667
建议:为代码示例使用 '代码示例' 格式。这是答案编辑器中的“零和”按钮。 – jwfearn 2008-09-24 15:39:05