I want to call a function of a class from exprtk. (http://www.partow.net/programming/exprtk/)
I want to register a function with this toolkit with symbol_table.add_function. Therefore it is required to derive my class like this from ifunction provided with that toolkit:
template <typename T>
struct foo : public exprtk::ifunction<T>
{
foo() : exprtk::ifunction<T>(0)
{}
T operator()()
{
// here I want to access data from a class which owns this struct
}
};
Is it possible to include this struct in a way, that a class can access it and the operator() of this struct can access data in the class? One possibility would be to pass a pointer of that class to the constructor of the struct. Is there a better way?
The state/data class can either own the
ifunction
or be passed in as a reference (be sure to manage life-times properly) or via astd::shared_ptr
to theifunction
instance: