Created
November 23, 2014 11:07
-
-
Save diazona/c03e80227f39cbdc4937 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <muParser.h> | |
#include <iostream> | |
#include <functional> | |
#include <boost/bind.hpp> | |
struct MyClass { | |
double m_arbitrary_value; | |
MyClass(int arbitrary_value) : m_arbitrary_value(arbitrary_value) {} | |
double make_a_value(double a, double b) {return m_arbitrary_value*a+b;} | |
}; | |
double wrapper(double a, double b, MyClass* p) { | |
return p->make_a_value(a, b); | |
} | |
int main(const int argc, const char** argv) { | |
// 1. just call the function | |
// this works fine | |
MyClass instance(5); | |
std::cout << wrapper(3, 2, &instance) << std::endl; | |
// 2. bind the function and call the resulting functor | |
// this works fine | |
std::cout << boost::bind(&wrapper, _1, _2, &instance)(3, 2) << std::endl; | |
// 3. pass the function to Parser::DefineFun | |
// this fails | |
mu::Parser p; | |
p.DefineFun("f", boost::bind(&wrapper, _1, _2, &instance)); | |
p.SetExpr("f(3, 2)"); | |
std::cout << p.Eval() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment