我在使用以下代码时遇到了编译问题:
template <typename T,
template <class T, class Allocator = std::allocator<T> > class C>
bool is_in(const C<T>& a, const C<T>& b);
template <typename T, std::vector> // HERE
bool is_in(const std::vector<T>& a, const std::vector<T>& b)
{
return false; // implementation tbd
}
...
vector<int> a, b;
cout << is_in(a,b) << endl;
错误消息是(在标记为“这里”的行上):
error: 'std::vector' is not a type
(当然,我已经包含了来自 std 的向量!)。有什么建议吗?我摆弄了一段时间,但我已经到了可以使用一些帮助的地步:-)我需要部分专门化初始模板声明,以便我可以让编译器根据实际类型切换实现容器 C(将有一个 is_in 用于集合,一个用于向量,一个用于范围......,每次使用不同的算法)。
谢谢!