【问题标题】:gdb: Could not find operator[]gdb:找不到运算符 []
【发布时间】:2014-05-14 16:20:22
【问题描述】:

我正在开发代码块,我有以下内容:

struct intersectionData_t
{
    unsigned int idxOfBlob;
    unsigned int idxOfRoad;
    ofPoint xPt; //interesection (cross) point
};

typedef vector<intersectionData_t> plineXD_t;

vector<plineXD_t> plinesXData;

基本上,每条折线都有一个在plineXD_t 中注册的交点向量。那么plinesXData就是所有折线的向量。

在我的实现中:

plineXD_t xData = findIntersectionData( trackedBlob , origRoads[i] );
if ( !xData.empty() ) 
    plinesXData.push_back( xData );

我稍后在代码中从plinesXData[i] 得到了一些奇怪的值,所以我想看看在xData 中生成了什么。

当代码块中的手表返回xData[0] : Could not find operator[]. 如果我尝试 plinesXData[i][0] 也是一样。

编辑:xData.size() 不返回数字(监视字段为空)。

EDIT2:findInterestionData 用在 2 条折线之间找到的所有交叉点 xPt 填充向量 intersectionData_t。它还存储每条折线的交叉点之前点的索引idxOfRoad &amp; idxOfBlob,以便快速访问。

path::plineXD_t path::findIntersectionData( \
            const ofPolyline& trackedBlob , const ofPolyline& road)
{
    plineXD_t xD;

    //for all line segments of path...
    for (unsigned int i = 0 ; i < road.size()-1 ; i++)
    {
        //...test all line segs of trackedBlob for intersections
        for (unsigned int j = 0 ; j < trackedBlob.size()-1 ; j++)
        {
            ofPoint intersectionPoint = ofPoint(0,0);

            if (ofLineSegmentIntersection(road[i] , road[i+1] , trackedBlob[j] , trackedBlob[j+1] , intersectionPoint ))
            {
                struct intersectionData_t id;
                id.idxOfRoad = i;
                id.idxOfBlob = j;
                id.xPt = intersectionPoint;

                xD.push_back( id );
            }
        }
    }

    return xD;
}

这是什么?如何查看 xData 向量的值?

【问题讨论】:

  • 也许发布一个更完整的代码清单会对试图提供帮助的人有所帮助

标签: c++ gdb codeblocks watch


【解决方案1】:

似乎T1 operator[](T2 smth) {...} 确实没有在结构plineXD_t 中定义,但您试图访问它。

如果您显示所有参与结构的完整代码会更好

【讨论】:

    【解决方案2】:

    不确定您的函数 findIntersectionData(trackedBlob , origRoads[i]) 是否真的返回一个向量,因为您没有显示完整的代码。但是,对于一个向量,您应该能够简单地通过使用 at() 成员函数来读取一个值。

    【讨论】:

      猜你喜欢
      • 2014-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      • 2015-07-15
      • 2021-06-08
      • 2013-12-04
      • 1970-01-01
      相关资源
      最近更新 更多