我想写一个简单的STL迭代器CArray MFC类使用boost迭代器适配器。这是我的代码:编译器错误与boost迭代器适配器
#include <boost/iterator/iterator_adaptor.hpp>
#include <afxtempl.h>
class CArrIter : public boost::iterator_adaptor< CArrIter ,
int,
int,
boost::random_access_traversal_tag >
{
public:
CArrIter(CArray<int,int>& arr, int index = 0) : m_arr(arr)
{
this->base_reference() = index;
}
private:
friend class boost::iterator_core_access;
int dereference() const{
return m_arr.GetAt(base());
}
private:
CArray<int,int>& m_arr;
};
这个编译良好的VC9编译器。但是当我尝试用VC7编译时,出现以下错误:
\include\boost\iterator\iterator_traits.hpp(49) : erro r C2039: 'difference_type' : is not a member of 'boost::detail::iterator_traits< Iterator>' with [ Iterator=int ]
\include\boost\mpl\eval_if.hpp(41) : see refer ence to class template instantiation 'boost::iterator_difference' bein g compiled with [ Iterator=int ]
.... Some more ....
任何线索什么可能是错误的?我必须包含一些其他头文件?我很兴奋提升图书馆。
的确,第二个参数(Base)将被用来确定其余的默认类型,并通过等价的'std :: iterator_traits'来传递它。由于OP没有指定'difference_type',因此当boost使用'boost :: detail :: iterator_traits'' – UncleBens 2010-02-01 16:18:51
'尝试执行编译时,编译失败,但是为什么它会使用VC9编译呢? – Naveen 2010-02-02 04:29:48
@Naveen:我不知道。但现在我想到了,也许你需要的实际上是iterator_facade? http://www.boost.org/doc/libs/1_41_0/libs/iterator/doc/iterator_facade.html – Manuel 2010-02-02 08:39:38