+ -
当前位置:首页 → 问答吧 → 为何同一个类里面一处有错,另一处没有错?

为何同一个类里面一处有错,另一处没有错?

时间:2011-12-05

来源:互联网

在local_from_world()这个函数里面, for(iter = shapes_.begin(); iter!= shapes_.end(); iter++)这一行出现错误:

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_Vector_const_iterator<_Ty,_Alloc>' (or there is no acceptable conversion)

但在render函数里面,同样这一行,却没错?

为啥?

代码如下

C/C++ code
Matrix3x3 CoordinateSystem::local_from_world() const
    {
    Matrix3x3 m;
    m.assignIdentity();

    std::vector<Shape*>::iterator iter;
    for(iter = shapes_.begin(); iter!= shapes_.end(); iter++)
    {
    if ((*iter)->parent()!=NULL)
        {
        m=(*iter)->parent()->local_from_parent()*m;
        }
    }
    return m;
    }
//在render函数里面却没有错?
void CoordinateSystem::render()
    {
    // push and post multiply the OpenGL modelview matrix by a transformation that
    // maps this coordinate system's local space into its parent space.

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
      Matrix3x3 mmd=parent_from_local();
      Matrix3x3 nnd=mmd.transpose();

       GLdouble m[16]={*(nnd[0]),*(nnd[0]+1),0,*(nnd[0]+2),*(nnd[1]),*(nnd[1]+1),0,*(nnd[1]+2),      0,0,1,0,       *(nnd[2]),*(nnd[2]+1),0,*(nnd[2]+2)};
              glMultMatrixd(m);

    std::vector<Shape*>::iterator iter;
    for(iter = shapes_.begin(); iter!= shapes_.end(); iter++)
    {
    (*iter)->render();
    }

    std::vector<CoordinateSystem*>::iterator CS_iter;
    for(CS_iter = children_.begin(); CS_iter != children_.end(); CS_iter++)
    {
    (*CS_iter)->render();
    }
    glPopMatrix();
    }

作者: superwavelet   发布时间: 2011-12-05

最好把shape贴出来看看!!!!!!!!!!

作者: neolyao   发布时间: 2011-12-05

这个错误显示的是迭代器类型(iterator)没有重载运算符“=”
即编译器不理解iter = shapes_.begin()该怎么赋值

至于为什么第二次出现没有问题
你将这两个函数的位置对调一下看看
如果还是同样的问题,也就是运算符重载的问题无疑了

作者: sxbwelcome   发布时间: 2011-12-05