#include
<iostream>
#include <boost/function.hpp>
#include <boost/bind.hpp>
using namespace std;
class Foo
{
public:
void foo(double d, int i, int j)
{
cout
<< d <<
endl;//打印0.5
cout
<< i <<
endl;//打印100
cout
<< j <<
endl;//打印10
}
};
int main()
{
Foo a;
boost::function<void
(int)> fp =
boost::bind(&Foo::foo,
&a, 0.5, _1, 10);
fp(100);
return 0;
}
#include <boost/function.hpp>
#include <boost/bind.hpp>
using namespace std;
class Foo
{
public:
};
int main()
{
}
本文展示了一个使用Boost库中的Bind函数和Function对象来绑定并调用类成员函数的例子。通过这种方式可以灵活地将类的方法作为参数传递,提高了程序的灵活性。
480

被折叠的 条评论
为什么被折叠?



