2012-05-21 4 views
0

구조체가있는 클래스와이 구조체가있는 목록이 있습니다.
하지만이 목록을 반복 할 때 속성을 구조체에서 가져올 수 없습니다.목록을 반복하는 동안 내 구조체의 속성을 가져올 수 없습니다.

오류 : 부재 'X_'에 대한 요구가 '_Tp = AStarPlanner와 it.std :: _ List_const_iterator < _Tp> :: * 연산자 :: 셀 *', 'AStarPlanner :: 셀이 아닌 클래스 타입 인 * const를 '

헤더 파일 :

class AStarPlanner { 

public: 

    AStarPlanner(int width, int height, const costmap_2d::Costmap2D* costmap); 

    virtual ~AStarPlanner(); 


protected: 

    struct Cell { 

     int x_; 
     int y_; 
     int f_; // f = g + h 
     int g_; // g = cost so far 
     int h_; // h = predicted extra cost 

     //CellInfo* visited_from_; // pointer to cell from which this cell is visited 

     Cell(int x, int y, int g, int h) : x_(x), y_(y), g_(g), h_(h) { 
       f_ = g_ + h_; 
     } 
    }; 

    bool cellInList(const Cell* cell, const std::list<Cell*> liste); 

    }; 

CPP 파일 :

bool AStarPlanner::cellInList(const Cell* cell, const list<Cell*> liste) 
{ 
    list<Cell*>::const_iterator it; 
    for (it = liste.begin(); it != liste.end(); it++) 
    { 
    if (it->x_ == cell->x_ && it->y_ == cell->y_) 
     return true; 
    } 

    return false; 
} 
+0

귀하의 초기 주장은 명백한 거짓이다 : 당신은 구조체의 목록이 아니라 * 포인터의 목록이 없습니다 *. –

답변

4

당신은 당신이 있도록하는 list<Cell*>이 이터레이터 인 을 역 참조 할 필요가있다.

for (it = liste.begin(); it != liste.end(); it++) 
{ 
    if ((*it)->x_ == cell->x_ && (*it)->y_ == cell->y_) 
     return true; 
} 
+0

글쎄, 당신은 나를 믿지 않을 것이다. 그러나 나는 그것을 시도했다, 일하지 않았다. 이제 다시 시도하고 작동 :) 나는 그것의 너무 늦은 나를 위해 생각 ... 감사합니다! – madmax

2

는 반복자 유형은 operator ->는 컬렉션의 요소 형식 무엇이든 반환에 과부하했다.

귀하의 경우, 이것은 Cell*입니다. Cell*은 포인터이고 Cell이 아니므로 x이 정의되지 않습니다. 실제 유형으로 가려면 다른 역 참조를해야합니다.

는 예컨대 :

if ((*it)->x_ == cell->x_ && (*it)->y_ == cell->y_) 
관련 문제