在C++中,何时以及如何使用回调函数?
编辑:
我想看一个简单的例子来编写回调函数.
所以,我正在尝试更好地学习模板元编程,我认为这是一个很好的练习.
我正在尝试编写可以使用我传递给它的任意数量的参数回调函数的代码.
// First function to call int add( int x, int y ) ; // Second function to call double square( double x ) ; // Third func to call void go() ;
回调创建代码应如下所示:
// Write a callback object that
// will be executed after 42ms for "add"
Callback<int, int, int> c1 ;
c1.func = add ;
c1.args.push_back( 2 ); // these are the 2 args
c1.args.push_back( 5 ); // to pass to the "add" function
// …