问题描述
我刚刚发布了一个跳过列表容器库.Sun 编译器对此抱怨:
I just released a skiplist container library. And the Sun compiler complains about this:
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())));
}
错误是:
"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.
上面的代码是从 207 开始的,但是好像在抱怨reverse_iterator.我真的无法理解.我无法直接访问 Sun 编译器,所以我想知道我是否做错了什么.
The code above is what starts at 207. But it seems that it's complaining about the reverse_iterator. I can't really make sense of it. I don't have direct access to the Sun compiler, so I was wondering if I'm doing something wrong.
另外,我只在 reverse_iterator 中使用了一个模板参数,但我注意到 SGI 文档说第二个参数 T 没有默认值.不过,我所看到的每个地方,他们都只使用这个:
Also, I'm only using one template argument in reverse_iterator, but I noticed the SGI documentation saying that there is no default for the second argument T. Everywhere I've looked though, they just use this:
typedef std::reverse_iterator<iterator> reverse_iterator;
这是编译器抱怨的第 65 行.我需要添加 T 作为参数吗?我无法弄清楚有问题的错误.
That's line 65 that the compiler complains about. Do I need to add T as a parameter? I can't figure out the error in question.
顺便说一句,这适用于我能找到的所有平台上的 gcc.它也适用于 Borland.
BTW, this works on gcc on all platforms I could find. And it works in Borland as well.
推荐答案
如 比较中所述C++ 标准库 libCstd 和 libstlport,Sun C++ 编译器附带了C++ 标准库"的两个实现:libCstd 和 libstlport.不幸的是,libCstd 不符合标准,但出于向后兼容性的原因,它是默认设置.除了其他差异之外,libCstd 版本的 std::reverse_iterator
模板使用了多个模板参数.
As explained at Comparing C++ Standard Libraries libCstd and libstlport, the Sun C++ compiler ships with two implementations of a "C++ standard library": libCstd and libstlport. Unfortunately, libCstd is not standards-conforming, but it is the default for backward-compatibility reasons. Among other differences, libCstd's version of the std::reverse_iterator
template uses more than one template parameter.
您需要通过传入编译器选项 -library=stlport4
来指示编译器使用 libstlport.
You need to instruct the compiler to use libstlport by passing in the compiler option -library=stlport4
.
另见:
- 当使用 libCstd 编译时,Boost 不会在 solaris 上构建 - 专注于 program_options
- 问题 53 - google-sparsehash - 在 SunOS CC 上编译失败编译器
这篇关于模板函数的模板参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!