fork download
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. #include <boost/function.hpp>
  6. #include <boost/bind.hpp>
  7.  
  8. using namespace std;
  9.  
  10. struct constrain{
  11. typedef boost::function<double(vector <double> &x_var)> callback_t;
  12. string name;
  13. int direction;
  14. callback_t evaluate;
  15. };
  16.  
  17. double func1(constrain *obj, vector<double> &p) {
  18. cout << obj->name << ", " << obj->direction << ", " << p.size() << endl;
  19. }
  20.  
  21. int main() {
  22. constrain ob;
  23. ob.name = "o";
  24. ob.direction = 1;
  25. vector<double> v(5);
  26.  
  27. ob.evaluate = boost::bind(&func1, &ob, _1);
  28. ob.evaluate(v);
  29. }
Success #stdin #stdout 0.01s 2864KB
stdin
Standard input is empty
stdout
o, 1, 5