iterator_facade with proxy reference type

Hi, could please somebody tell me why the code below generates a compile-time error? The compiler I'm using is VC++ 7.1. The error generated is this: c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(458) : error C2582: 'operator =' function is unavailable in 'item_proxy' c:\PROG\VCPP\xItFacadeReferProxy\xItFacadeReferProxy.cpp(102) : see reference to function template instantiation 'void std::generate<array_iterator,int(__cdecl *)(void)>(_FwdIt,_FwdIt,_Fn0)' being compiled with [ _FwdIt=Array_iterator, _Fn0=int (__cdecl *)(void) ] the location of the error in <algorithm>: template<class _FwdIt, class _Fn0> inline void generate(_FwdIt _First, _FwdIt _Last, _Fn0 _Func) { // replace [_First, _Last) with _Func() for (; _First != _Last; ++_First) *_First = _Func(); // ERROR HERE } To my best knowledge, item_proxy's operator= is public, so I don't understand why it is unavailable. Thx, Gus The code: ------------------------------------------------------------------------ // xItFacadeReferProxy.cpp : Defines the entry point // for the console application. #include "stdafx.h" #include <algorithm> #include <boost/iterator/iterator_facade.hpp> using namespace boost; using namespace std; // THIS CLASS IS GOING TO BE 'STL'IZED': const int ARRAY_SIZE = 10; class Array { public: int Get(int i) const { return data[i]; } int Set(int i, int val) { data[i] = val; } private: int data[ARRAY_SIZE]; };//class Array class item_proxy; class Array_iterator : public iterator_facade < Array_iterator, int, // VALUE TYPE boost::random_access_traversal_tag, item_proxy // REFERENCE TYPE > { public: class item_proxy { public: item_proxy(const Array_iterator &it): m_rIterator(it) {} item_proxy& operator=(int i) { m_rIterator.m_pArray-> Set(m_rIterator.m_index, i); return *this; } item_proxy& operator=(item_proxy const& rhs) { operator=((int)rhs); return *this; } operator int() const { return m_rIterator.m_pArray-> Get(m_rIterator.m_index); } private: Array_iterator const &m_rIterator; };//class item_proxy public: Array_iterator():m_pArray(0) {} Array_iterator(Array& array, int index = 0): m_pArray(&array), m_index(0) {} private: friend class boost::iterator_core_access; void increment() { ++m_index; } void decrement() { --m_index; } void advance(int n) { m_index += n; } int distance_to(Array_iterator const& rhs) { if(m_pArray != rhs.m_pArray) { return -1; } return rhs.m_index - m_index; } bool equal(Array_iterator const& rhs) const { return m_pArray == rhs.m_pArray && m_index == rhs.m_index; } item_proxy dereference() const { return item_proxy(*this); } Array *m_pArray; int m_index; };//class Array_iterator Array_iterator array_begin(Array& array) { return Array_iterator(array); } Array_iterator array_end(Array& array) { return Array_iterator(array, ARRAY_SIZE); } int value_generator() { static int i = 0; return ++i; } int _tmain(int argc, _TCHAR* argv[]) { Array a; generate(array_begin(a), array_end(a), value_generator); // ERROR! copy(array_begin(a), array_end(a), ostream_iterator<int>(cout, " ")); return 0; } ------------------------------------------------------------------------

gusz1@freemail.hu writes:
Hi, could please somebody tell me why the code below generates a compile-time error? The compiler I'm using is VC++ 7.1.
The item_proxy declared inside your iterator class and the one declared outside and used as its reference type are distinct classes. The one outside is an incomplete type, so no operator= is available. HTH, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
participants (2)
-
David Abrahams
-
gusz1ļ¼ freemail.hu