模板 + Boost::Function。示例代码:
#include
<
string
>
#include < iostream >
#include < boost / function.hpp >
using namespace std;
using namespace boost;
class Test
{
public :
Test(){};
virtual ~ Test(){};
void Handle( string & s, unsigned int lines)
{
for ( int i = 0 ; i < lines; i ++ )
{
cout << s << endl;
}
};
};
template < class T >
static void CallBack(T & t, boost::function < void (T * , string & , unsigned int ) > f)
{
string s( " test " );
f( & t, s, 3 );
};
int main()
{
Test test;
CallBack < Test > (test, & Test::Handle);
return 0 ;
}
#include < iostream >
#include < boost / function.hpp >
using namespace std;
using namespace boost;
class Test
{
public :
Test(){};
virtual ~ Test(){};
void Handle( string & s, unsigned int lines)
{
for ( int i = 0 ; i < lines; i ++ )
{
cout << s << endl;
}
};
};
template < class T >
static void CallBack(T & t, boost::function < void (T * , string & , unsigned int ) > f)
{
string s( " test " );
f( & t, s, 3 );
};
int main()
{
Test test;
CallBack < Test > (test, & Test::Handle);
return 0 ;
}
本文转自xiaotie博客园博客,原文链接http://www.cnblogs.com/xiaotie/archive/2006/04/06/368221.html如需转载请自行联系原作者
xiaotie 集异璧实验室(GEBLAB)