Hello everyone,
I am currently struggling to get the following code to compile. First the header file containing a class with a method template:
// ConfigurationContext.h
class ConfigurationContext
{
public:
template<typename T> T getValue(const std::string& name, T& default) const
{
...
}
}
Somewhere else I want to call this method like this:
int value = context.getValue<int>("foo", 5);
There I get the following error:
error: no matching function for call to 'ConfigurationContext::getValue(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, int)'
I checked the obvious errors like missing includes and stuff like that. But everything seems to be right. I tried removing the pass-by-reference of the template type argument like this:
template<typename T> T getValue(const std::string& name, T default) const ...
Then it compiles without any errors and also runs fine, but I'd still like to pass in a reference here...
Does anybody know whats happening here and how to make this work?