I have a "set" data type:
template <class V>
struct Set {
void add(const V& value) {}
};
I want to write a top-level function version of Set::add
.
template <class V>
void add(const Set<V>& set, const V& value) {}
This doesn't quite work with string literals:
Set<const char*> set;
const char* val = "a";
set.add(val); // ok
set.add("a"); // ok
add(set, val); // ok
add(set, "a"); // ERROR
add<const char*>(set, "a"); // ok
The error message (g++ 4.2.4):
no matching function for call to ‘add(Set<const char*>&, const char [2])’
It looks it has something to do with the fact that "a"
has type const char[2]
and not const char*
. Does anybody know how to get this to work?