I have the following function that takes a symbol table and adds a composited function to the symbol table:
void add_function(exprtk::symbol_table<double>& symtab) {
using compositor_t = exprtk::function_compositor<double>;
using function_t = typename compositor_t::function;
compositor_t compositor(symtab);
const bool res = compositor.add(
function_t("incrementor")
.var("x")
.expression
( " x + 1; " ));
if (!res) {
printf("comp err!");
}
}
Later on I call the add function and then compile an expression that uses the sym table
using symbol_table_t = exprtk::symbol_table<double>;
using expression_t = exprtk::expression<double>;
using parser_t = exprtk::parser<double>;
double x = 123.0;
symbol_table_t symbol_table;
expression_t expression;
parser_t parser;
symbol_table.add_variable("x", x);
add_function(symbol_table);
expression.register_symbol_table(symbol_table);
const std::string program = "incrementor(x)";
if (!parser.compile(program,expression)) {
printf("err: %s\n",parser.error().c_str());
return;
}
However the parser.compile
returns false, and I get the following error:
Error: ERR232 - Undefined symbol: 'incrementor'
I've checked the sym table using a debugger and the incrementor function is not there. Not sure why or how the incrementor symbol disappears between the call to add_function and compile.