That might be a silly question, but I'm staring at this code for a while and can't think of what's wrong. On compiling:
#include <string>
#include <map>
template <typename T>
struct my_string_map {
typedef std::map<std::string, T> type;
};
template <typename T> bool add_to_string_map(my_string_map<T>::type map,
std::string str, T x) {
if (map.find(str) != map.end())
return false;
map[str] = x;
return true;
}
I get:
foo.cpp:8: error: template declaration of ‘bool add_to_string_map’
foo.cpp:8: error: expected ‘)’ before ‘map’
foo.cpp:8: error: expected primary-expression before ‘str’
foo.cpp:8: error: expected primary-expression before ‘x’
(Definition of my_string_map class was taken from another thread of this forum)
When i specialize what template type I'm using, like in
bool add_to_string_int_map(my_string_map<int>::type map,
std::string str, int x) {
if (map.find(str) != map.end())
return false;
map[str] = x;
return true;
}
everything works fine. Why it's not working and/or how to get it working?
Thanks in advance for your help