2012-01-13 140 views
0

我在我的头文件中的下列减速VC++矢量迭代器初始化

// 3D Vector 
typedef struct tagV3D /*: V2D*/ { 
    union { 
    struct { 
      double x; 
      double y; 
      double z; 
    }; 
    struct { 
      struct tagV2D v2d_; 
    }; 
}; 
} V3D, TVec3D, *PVec3D; 

现在我有我的cpp文件中的方法

bool InsertSelfIntersectionVertexes(vector<PVec3D> &avtxlst) { 

    PVec3D vtx; 
    int iI; 
    ... 

    vtx = new TVec3D; 
    *vtx = v; 
    PVec3D* p= avtxlst.begin() + iI + 1; 
    avtxlst.insert(p, vtx); 

    ... 
    } 

我得到以下尝试编译代码中的错误

error C2440: 'initializing' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'PVec3D *'
and
error C2664: 'std::_Vector_iterator<_Ty,_Alloc> std::vector<_Ty>::insert(std::_Vector_const_iterator<_Ty,_Alloc>,const _Ty &)' : cannot convert parameter 1 from 'PVec3D' to 'std::_Vector_const_iterator<_Ty,_Alloc>'

我该如何解决这个问题?

下面的代码工作正常与VC6,当迁移到VS 2008出现了错误。
这是为什么?
欣赏任何答案

+0

为什么* PVec3D不是PVec3D,那就是没有明星? – 2012-01-13 10:16:22

回答

3

A vector<T>::iterator是一种单独的类型,与指向结构的指针不兼容。您应该创建一个vector<PVec3D>::iterator my_iter = avtxlst.begin()

现在,您可以对迭代器执行相同的操作,就像使用指针一样。如增量,my_iter++或解除引用*my_iter

然后,您可以使用my_iter并将其增加Ii以及任何您需要执行的操作。