迭代器中的非标准语法错误?(c++)

Non standard syntax error in iterator? (C++)

本文关键字:c++ 错误 语法 非标准 迭代器      更新时间:2023-10-16
void PointCloud::Create(std::vector<std::vector<cv::Point3d>> threeDPointSpace){
    std::vector<std::vector<cv::Point3d>>::iterator row;
    std::vector<cv::Point3d>::iterator col;
    for (row = threeDPointSpace.begin(); row != threeDPointSpace.end(); row++) {
        for (col = row->begin(); col != row->end(); col++) {
            cv::Point3d thisOne = col._Getcont; // error reported here
            vertices.push_back(VertexFormat(glm::vec3(thisOne.x, thisOne.y, thisOne.z), glm::vec4(1.0, 0.0, 1.0, 1.0)));
            totalData++;
        }
    }
}

错误信息读取:

严重性代码描述项目文件行错误C3867 'std::_Iterator_base12::_Getcont':非标准语法;使用'&'创建指向成员

的指针

这是什么意思?我该如何解决这个问题?我没有正确使用这个迭代器模式吗?我正在尝试访问这些元素

您试图使用函数std::vector<cv::Point3d>::iterator::_Getcont而不调用它(())或使用语法地址(&),这确实是非标准的。

cv::Point3d thisOne = col._Getcont();

然而,这个函数是来自Visual Studio的标准库实现的内部(主要线索是_和cppreference.com的文档中没有提到RandomAccessIterator的公共接口);我不知道你为什么要用它。只要解引用迭代器,就像其他人一样:

const cv::Point3d& thisOne = *col;

由于colstd::vector<cv::Point3d>::iterator,您必须使用

Point3d访问属性
cv::Point3d thisOne = col->_Getcont;

如果这是一个方法,确保你调用了

方法
cv::Point3d thisOne = col->_Getcont();

你不应该使用?

cv::Point3d thisOne = col->_Getcont;

或者if _Getcont是成员函数

cv::Point3d thisOne = col->_Getcont();

cv::Point3d thisOne = ( *col )._Getcont;
cv::Point3d thisOne = ( *col )._Getcont();

或者你可以直接写

cv::Point3d thisOne = *col;

,因为左对象的类型与表达式*col的类型相同。

在这种情况下,函数可以写成

void PointCloud::Create(std::vector<std::vector<cv::Point3d>> threeDPointSpace)
{
    for ( auto &row : threeDPointSpace )
    {
        for ( auto &thisOne : row )
        {
            vertices.push_back(VertexFormat(glm::vec3(thisOne.x, thisOne.y, thisOne.z), glm::vec4(1.0, 0.0, 1.0, 1.0)));
            totalData++;
        }
    }
}