I have a Parameter class and I've overloaded the constructor to accept bools or doubles. When you give it an int, it fails to build:
error C2668: 'Parameter::Parameter' : ambiguous call to overloaded function could be 'Parameter::Parameter(std::string,std::string,double)' or
'Parameter::Parameter(std::string,std::string,bool)'
I believe I have two options:
- Overload with an int default
- Explicitly convert my variable to a double
I have a ton of Parameters, and some of them are unsigned long, floats, etc. (in a project multiple people support), so neither of these are perfect solutions. Is there any way to force an implicit conversion from int to double? Thanks.
Code:
#include <string>
#include <unordered_map>
using namespace std;
class Parameter
{
public:
enum eVarType { BOOL, NUMBER};
Parameter() {};
Parameter( string param_name, string param_description, bool dft ) { type_ = BOOL;};
Parameter( string param_name, string param_description, double dft ) { type_ = NUMBER;};
private:
eVarType type_;
};
class ParameterManager
{
public:
template<typename T> void add( string option_name, string description, T value );
private:
std::unordered_map< string, Parameter > parameters;
};
template<typename T> void ParameterManager::add( string param, string description, T value )
{
parameters[param] = Parameter( param, description, value );
};
int main()
{
ParameterManager mgr;
int var = 1;
mgr.add("number","This is an int",var); //Could be double or bool: I want it to be a double
}