Hi,
I have a code which gets compiled using gcc 2.3. However I am getting some errors with gcc 3.4.6.
Here is the code snippet:
I get below errors with gcc 3.4.6:Code:NAMESPACE_BEGIN(utils) // // template class list // template <class _Ty> class list { protected: // // struct Node & Nodeptr // - Each element in the list is a struct Node // struct Node; friend struct Node; typedef Node *Nodeptr; public: // // This is what is being defined (the type of 'this') // typedef list<_Ty> _Myt; // // Forward & friend declarations for the iterators // class iterator; friend class iterator; class const_iterator; friend class const_iterator; // // iterator() // class iterator { public: // Constructors iterator() { } iterator(Nodeptr __P) : _Ptr(__P) { } _Ty &operator *() const { return Acc::Value(_Ptr); } // Prefix ++ iterator& operator ++() { _Ptr = Acc::Next(_Ptr); return (*this); } // Postfix ++ iterator operator ++(int) { iterator _Tmp = *this; ++*this; return (_Tmp); } // Prefix -- iterator& operator --() { _Ptr = Acc::Prev(_Ptr); return (*this); } // Postfix -- iterator operator --(int) { iterator _Tmp = *this; --*this; return (_Tmp); } bool operator ==(const iterator& __X) const { return (_Ptr == __X._Ptr); } bool operator !=(const iterator& __X) const { return (!(*this == __X)); } Nodeptr Mynode() const { return (_Ptr); } protected: Nodeptr _Ptr; }; // end iterator // // const_iterator // class const_iterator : public iterator { public: // Constructors const_iterator() { } const_iterator(Nodeptr __P) : iterator(__P) { } const_iterator(const iterator& __X) : iterator(__X) { } const _Ty& operator *() const { return (Acc::Value(_Ptr)); //error: line 148 `_Ptr' was not declared in this scope } // Prefix ++ const_iterator& operator ++() { _Ptr = Acc::Next(_Ptr); //error: line 154 `_Ptr' was not declared in this scope return (*this); } // Postfix ++ const_iterator operator ++(int) { iterator _Tmp = *this; ++*this; return (_Tmp); } // Prefix -- const_iterator& operator --() { _Ptr = Acc::Prev(_Ptr); //error: line 169 `_Ptr' was not declared in this scope return (*this); } // Postfix -- const_iterator operator --(int) { iterator _Tmp = *this; --*this; return (_Tmp); } bool operator ==(const const_iterator& __X) const { return (_Ptr == __X._Ptr); //error: line 183 `_Ptr' was not declared in this scope } bool operator !=(const const_iterator& __X) const { return (!(*this == __X)); } }; // end const_iterator
It will be highly appreciated if someone can please shed some light on this?Code:../include/list.h:148: error: `_Ptr' was not declared in this scope ../include/list.h: In member function `utils::list<_Ty>::const_iterator& utils::list<_Ty>::const_iterator::operator++()': ../include/list.h:154: error: `_Ptr' was not declared in this scope ../include/list.h: In member function `utils::list<_Ty>::const_iterator& utils::list<_Ty>::const_iterator::operator--()': ../include/list.h:169: error: `_Ptr' was not declared in this scope ../include/list.h: In member function `bool utils::list<_Ty>::const_iterator::operator==(const utils::list<_Ty>::const_iterator&) const': ../include/list.h:183: error: `_Ptr' was not declared in this scope




Reply With Quote