「セット」データ型があります。
template <class V>
struct Set {
void add(const V& value) {}
};
のトップレベル関数バージョンを書きたいですSet::add
。
template <class V>
void add(const Set<V>& set, const V& value) {}
これは、文字列リテラルではうまく機能しません。
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
エラー メッセージ (g++ 4.2.4):
no matching function for call to ‘add(Set<const char*>&, const char [2])’
"a"
が type を持っていて を持ってconst char[2]
いないという事実と関係があるようですconst char*
。これを機能させる方法を知っている人はいますか?