我有一堆类实现基于顶点的几何对象,如TriangleMesh,PointClouds或Edgesets。它们都从VertexBasedGeometry继承。我现在希望它们都返回一个双向迭代器对其顶点的引用。这将允许以非模板方式访问任何VertexBasedGeometry的顶点。现在,我对迭代器不太熟悉,事实证明这很困难。我尝试如下所示:所有双向迭代器的常见类类型C++
class VertexBasedGeometry : public Geometry
{
public:
typedef std::iterator<std::bidirectional_iterator_tag,defines::Vector3 > VertexIterator;
VertexBasedGeometry(){};
virtual VertexIterator begin()=0;
virtual VertexIterator end()=0;
};
在TraingleMesh,从VertexBasedGeometry继承我现在尝试实现该功能首先返回其中包含了顶点的std ::向量的开始迭代器。这将导致以下编译器错误的GCC 4.2(苹果):现在
Mesh.cpp:25: error: conversion from '__gnu_cxx::__normal_iterator<defines::Vector<double, 3>*, std::vector<defines::Vector<double, 3>, std::allocator<defines::Vector<double, 3> > > >' to non-scalar type 'std::iterator<std::bidirectional_iterator_tag, defines::Vector<double, 3>, long int, defines::Vector<double, 3>*, defines::Vector<double, 3>&>' requested
我的问题是:为什么这个不行,我应该怎么改变这种得到它的工作? 阅读关于迭代器的更多信息,我有一种轻微的感觉,我无法找到任何双向迭代器的通用类型,是吗?有些类可能会将其顶点存储在std :: vector之外的其他容器中,其他类已经提供了(非stl符合)迭代器,这些迭代器我想适应我的常见类型。我愿意接受任何有关如何实施的建议。
我现在就试试看。首先必须阅读any_pointer。谢谢,@thiton –