我正在尝试为自定义容器专门定制std::begin
。我这么做是因为我想使用基于范围的for
循环来遍历容器。这是我的代码:
class stackiterator { … };
class stack { … };
#include <iterator>
template <> stackiterator std::begin(stack& S)
{
return S.GetBottom();
}
在我对 begin
进行特化的定义处,我遇到了以下错误:
没有匹配函数模板的函数模板特化 'begin'
我做错了什么?
stack::begin()
,并直接使用std::begin()
的实现呢? - R Sahustd::begin
,因为[请参见我的先前评论]。 - emlaibegin
函数。这很混乱,Eric Niebler提出了一个解决方案,使std::begin
(和其他自定义点)可以做到这一点,这样我们就不会在函数顶部有一堆重复的using语句,随着自定义点列表的增长而变得越来越大。 - chris