小编Vor*_*ath的帖子

模板函数的模板参数

我刚刚发布了一个skiplist容器库.Sun编译器抱怨这个:

template <class T, class R>
bool operator==(const IndexedSkipList<T,R> &left, const IndexedSkipList<T,R> &right)
{
  return ((left.size() == right.size()) &&
          (std::equal(left.begin(), left.end(), right.begin())));
}
Run Code Online (Sandbox Code Playgroud)

错误是:

"include/CSIndexedSkipList.h", line 65: Error: Too few arguments for template std::reverse_iterator<CS::BidiIdxIterator<CS::IndexedSkipList<CS::T, CS::R>>>.
"include/CSIndexedSkipList.h", line 207:     Where: While specializing "CS::IndexedSkipList<CS::T, CS::R>".
"include/CSIndexedSkipList.h", line 207:     Where: Specialized in non-template code.
Run Code Online (Sandbox Code Playgroud)

上面的代码是从207开始的.但似乎它在抱怨reverse_iterator.我真的无法理解它.我没有直接访问Sun编译器,所以我想知道我做错了什么.

另外,我只在reverse_iterator中使用了一个模板参数,但是我注意到SGI文档说第二个参数没有默认值T.我看过的地方,他们只是使用它:

typedef std::reverse_iterator<iterator> reverse_iterator;
Run Code Online (Sandbox Code Playgroud)

那是编译器抱怨的第65行.我需要添加T作为参数吗?我无法弄清楚有问题的错误.

顺便说一句,这适用于我能找到的所有平台上的gcc.它也适用于Borland.

c++ templates stl

9
推荐指数
1
解决办法
1484
查看次数

标签 统计

c++ ×1

stl ×1

templates ×1