ฉันได้ใช้ตัววนซ้ำเช่นนี้
template <typename GridT,
typename GridPtr,
typename GridRef,
template <typename> class ShapeT>
class GridIterator
{
public:
typedef GridIterator<GridT, GridPtr, GridRef, ShapeT> Iterator;
// Iterator traits - typedefs and types required to be STL compliant
typedef std::ptrdiff_t difference_type;
typedef typename GridT::Element value_type;
typedef typename GridT::Element* pointer;
typedef typename GridT::Element& reference;
typedef size_t size_type;
typedef std::forward_iterator_tag iterator_category;
GridIterator(GridT& grid,
ShapeT<typename GridT::Resolution> shape,
Index iterStartIndex);
~GridIterator();
Iterator& operator++();
Iterator operator++(int);
typename GridT::Element& operator*();
typename GridT::Element* operator->();
bool operator==(const GridIterator& rhs) const;
bool operator!=(const GridIterator& rhs) const;
private:
GridT& grid_;
ShapeT<typename GridT::Resolution> shape_;
Index iterIndex_;
Index iterIndexEnd_;
};
มันทำงานได้ดีกับ std::generate และ std::find แต่เมื่อฉันใช้กับ std::max_element ฉันได้รับข้อผิดพลาด:
main.cpp: ในฟังก์ชัน 'int main(int, const char**)': main.cpp:105:16: ข้อผิดพลาด: 'iter' ไม่ได้ถูกประกาศในขอบเขตนี้ ในไฟล์ที่รวมมาจาก /usr/include/c++/4.6 /algorithm:63:0, จาก ./grid/Map_Grid.h:11, จาก main.cpp:4: /usr/include/c++/4.6/bits/stl_algo.h: ในฟังก์ชัน '_FIter std::max_element(_FIter , _FIter) [ด้วย _FIter = Map::GridIterator, Map::Grid*, Map::Grid&, Map::Rectangle>]': main.cpp:102:53:
สร้างอินสแตนซ์จากที่นี่ /usr/include/ c++/4.6/bits/stl_algo.h:6243:4: ข้อผิดพลาด: การใช้ฟังก์ชันที่ถูกลบ 'Map::GridIterator, Map::Grid*, Map::Grid&, Map::Rectangle>& Map::GridIterator, Map: :Grid*, Map::Grid&, Map::Rectangle>::operator=(const Map::GridIterator, Map::Grid*, Map::Grid&, Map::Rectangle>&)' ในไฟล์รวมมาจาก ./ grid/Map_Grid.h:8:0 จาก main.cpp:4: ./grid/Map_GridIterator.h:17:8: ข้อผิดพลาด: 'Map::GridIterator, Map::Grid*, Map::Grid&, Map: :สี่เหลี่ยมผืนผ้า>& แผนที่::GridIterator, แผนที่::Grid*, แผนที่::Grid&, แผนที่::สี่เหลี่ยมผืนผ้า>::operator=(const Map::GridIterator, แผนที่::Grid*, แผนที่::Grid&, แผนที่:: สี่เหลี่ยมผืนผ้า>&)' ถูกลบโดยปริยายเนื่องจากคำจำกัดความเริ่มต้นจะมีรูปแบบไม่ถูกต้อง: ./grid/Map_GridIterator.h:17:8: ข้อผิดพลาด: สมาชิกอ้างอิงที่ไม่คงที่ 'Map::Grid& Map::GridIterator, Map:: Grid*, Map::Grid&, Map::Rectangle>::grid_' ไม่สามารถใช้ตัวดำเนินการกำหนดค่าเริ่มต้นได้
มีความคิดเห็นเกี่ยวกับสิ่งที่ฉันทำผิดหรือไม่?