int width = config["width"]; But since it returns strings this doesn't work. I thought that I'd overload the subscript operator so that it returns any type with the help of templates. I wrote this function:
template<class T> const T& Config::operator[] (const string &name)
{
if(mReader[name].empty())
{
return StringTo<T>(mDefaults[name]);
}
return StringTo<T>(mReader[name]);
}
This function checks whether a value has been read from file, otherwise it returns a default value. StringTo