我實現了像迭代這樣自定義迭代器
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 ::生成和std ::發現,但是當我的std :: max_element使用它,我得到了自己的錯誤:
main.cpp: In function ‘int main(int, const char**)’: main.cpp:105:16: error: ‘iter’ was not declared in this scope In file included from /usr/include/c++/4.6/algorithm:63:0, from ./grid/Map_Grid.h:11, from main.cpp:4: /usr/include/c++/4.6/bits/stl_algo.h: In function ‘_FIter std::max_element(_FIter, _FIter) [with _FIter = Map::GridIterator, Map::Grid*, Map::Grid&, Map::Rectangle>]’: main.cpp:102:53:
instantiated from here /usr/include/c++/4.6/bits/stl_algo.h:6243:4: error: use of deleted function ‘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>&)’ In file included from ./grid/Map_Grid.h:8:0, from main.cpp:4: ./grid/Map_GridIterator.h:17:8: error: ‘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>&)’ is implicitly deleted because the default definition would be ill-formed: ./grid/Map_GridIterator.h:17:8: error: non-static reference member ‘Map::Grid& Map::GridIterator, Map::Grid*, Map::Grid&, Map::Rectangle>::grid_’, can’t use default assignment operator
有關我在做什麼錯的任何想法?
這聽起來不可能在沒有實施的情況下回答你。錯誤日誌僅表明執行了非法複製分配。 – 2014-12-07 01:55:48