I'm trying to write a set of functions which converts strings to their corresponding numeric value, "int, float, double..." but My templated function is not recognized by the c++ compiler.
When I call it, I get a message stating "No matching Function for call. I was returning a function of type T from this function, but I had this error message, I've tried modifying the function so it could change the value of a variable passed by reference, but the error persists.
I've tried modifying this function but it t doesnt still works please help. I have several versions of this function which are overriden, as follows:
static void convertValue(eOperandType type, const std::string &value, FloatOperandType typeDeterminer, T &container) { try { container = std::stof(value); } catch (std::invalid_argument e) { throw AVMException("The value passed as number is not valid"); } catch (std::out_of_range e) { char *msg = "The value passed is out of the range of the typed passed"; throw AVMException(msg); } catch (exception& e) { throw AVMException("An unexpected error occured when converting value types"); } } template <typename T> static void convertValue(eOperandType type, const std::string &value, IntOperandType typeDeterminer, T &container) { int val = 0; try { val = std::stoi(value); switch(type) { case eOperandType::Int8: if(val < -128 || val > 127) throw AVMWarnException("Overflow for type Int8"); case eOperandType::Int16: if(val < -32768 || val > 32,767) throw AVMWarnException("Overflow for type Int16"); case eOperandType::Int32: if(val < -2147483648 || val > 2147483647) throw AVMWarnException("Overflow for type Int32"); } container = std::stoi(value); } catch (std::invalid_argument e) { throw AVMException("The value passed as number is not valid"); } catch (std::out_of_range e) { char *msg = "The value passed is out of the range of the typed passed"; throw AVMException(msg); } catch (exception& e) { throw AVMException("An unexpected error occured when converting value types"); } } Here is how I call the function:
int v = 0; Converter::convertValue<int>("20", eOperandType::Int8, IntOperandType::_Int8, &v);