So, I have been trying to add a function where you pass a string that is a function (such as "sin(x)") and some bounds and it graphs the line by making a GL_LINE_STRIP. I wrote the function based off of the example 1 that the developer made. Here is the function I have created. //Excerpt from draw.h template void GraphY(std::string ln) { typedef exprtk::symbol_table symbol_table_t; typedef exprtk::expression expression_t; typedef exprtk::parser parser_t;
T x;
symbol_table_t symbol_table;
symbol_table.add_variable("x", x);
symbol_table.add_constant();
expression_t expression;
expression.register_symbol_table(symbol_table);
parser_t parser;
parser.compile(ln, expression);
glLineWidth(w);
glColor4f(outline.r / 255, outline.g / 255, outline.b / 255, outline.a / 255);
glBegin(GL_LINE_LOOP);
for (x = T(-5); x <= T(+5); x += T(0.001))
{
T y = expression.value();
glVertex3f(x, y, 0);
}
glEnd();
}
This function appears to have no errors and I am fairly sure it will work pretty well once calling it works. I have a function that is calling this function (it is inside of a different file). It does it like this.
//Excerpt from render.cpp
GraphY("sin(x)");
It produces the following error
1>Render.obj : error LNK2019: unresolved external symbol "void __cdecl GraphY(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?GraphY@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "void __cdecl Render(void)" (?Render@@YAXXZ)
Although this error has already been asked I really don't know how to fix it because I am not familiar with templates or the inter workings of exprtk.hpp. I was hoping someone could help me.
I have checked and it is not because it cant find the function. Something is just going wrong. I suspect this is because of templates. Which although I have read up on I really don't understand. However I have gathered that somehow I am supposed to call the function like this:
GraphY<somedatatype>("sin(x)");
However I don't know what datatype to put in their to make it happy. Could you please help me get this function to work? You can download the library (exprtk.hpp) from https://github.com/ArashPartow/exprtk. You can also see how you are supposed to use the library in code (unfortunately he doesn't have any examples where he makes a function like this).
Thanks much!