-1

大家好,当我在函数本身中使用向量迭代器时出现编译错误。

我已经尝试从http://ideone.com/tTDYU5执行示例,它工作得非常好。然而,当我试图把它放在一个函数中时,事情变得丑陋了,为什么会这样?

vector <PointTwoD> topfive;
void MissionPlan::topfives()
{   
    topfive.assign( point1.begin(), point1.end() ); 
    sort(topfive.begin(), topfive.end(), sortByCiv);
}

void MissionPlan::DisplayTopFiveResult()
{
    missionplan.topfives();

    vector<PointTwoD>::iterator it = topfive.begin();
    for (int i = 0; i < 5 && it != topfive.end(); i++) {
    cout <<  "X axis: " << pointtwoD.xcord  << "          " << "Y axis: " << pointtwoD.ycord <<  "          " << "CIV Index: " << pointtwoD.civIndex << *it;
    ++it;
    }


}
4

1 回答 1

0

由于“值都在类中PointTwoD

用于it打印那些:

vector<PointTwoD>::iterator it = topfive.begin();
    for (int i = 0; i < 5 && it != topfive.end(); i++) {
    cout <<  "X axis: "  << it->xcord  << " " 
         <<  "Y axis: "  << it->ycord  << " " 
         << "CIV Index: " << it->civIndex << std::endl;
    ++it;
    }

如果这仍然引发编译错误,您需要提供更多信息。

于 2013-10-27T08:44:49.357 回答