A C++ program with user-defined variables

149 Views Asked by At

I'm writing a code that implements simple command line calculator, and I wanted to add a function for user to create his own variables with numeric values for better calculations. Can anyone share any advice, what technique should I use? I thought about creating an allocated two-dimensional string array and later just converting numeric values or use a template, something like that:

template<class T>
void UserVariables(T varname, T varvalue){
T tArray[2][MAX_VARS]={ {varname1, varvalue1}, {varname2, varvalue2}, ... };
....
}

Maybe there are any better and less noobie-ish decisions out there? Thanks in advance.

2

There are 2 best solutions below

1
On BEST ANSWER
0
On

I don't see how your attempt would work - templates are evaluated at compile time, not run time, so the user can't make new variables one the code is running.