boost::functionを使ってなんでもコールバックできる関数を作る。
void loop(int n, boost::function<void(int)> callback) { for(int i = 0; i < n; ++i) { callback(i); } } void foo(int n); class Bar { public: void operator () (int n); }; void test() { // 関数を与える loop(10, foo); // 関数オブジェクトを与える Bar bar; loop(10, bar); // boost::lambdaのlambda式を与える loop(10, std::cout << boost::lambda::_1 << "\n"); }