先发下超越Boost库中的一个代码 #include <iostream> #include "boost/function.hpp" bool some_func(int i ,double d) { return i>d; } int main() { boost::function<bool(int,double)> f; f=&some_func; std::cout<<f(1,2.0)<<std::endl; system("pause"); return 1; } 当我敲完这段代码的时候 感觉这bu就是回调函数嘛 接下来就是传统的回调函数的说明 如下: #include <iostream> #include <vector> #include <algorithm> #include "boost/function.hpp" void print1(int i) { std::cout<<"ipnut is: "<<i<<std::endl; } void print2(int i) { std::cout<<"ipnut at now is: "<<i<<std::endl; } class notif { typedef void (*fun_type)(int); std::vector<fun_type> vec_; int value; public: void add_obv(fun_type t){vec_.push_back(t);} void change_value(int i) { value = i; for(std::size_t i=0;i<vec_.size();i++) (vec_[i](value)); } }; int main() { notif n; n.add_obv(&print1); n.add_obv(&print2); n.change_value(8); system("pause"); return 1; }