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?
foo
fromexprtk::ifunction<>
and your other class. Without more context it is hard to say which one is the best (or most appropriate). This said, some ad.: If you don't need the complete power of exprtk, you may consider to build your own expression parser. This might be a start: SO: The Tiny Calculator Project. – Depurateoperator()()
or usage in exprtk. But if instances of multiple classes (inherited from exprtk::ifunction<T>) have to share the data of the same instance of your class then multi inheritance is, of course, not an option. In that case, pointer or reference... – Depurate