Can somebody explain why gcc throws:
lst_iterators.h: In member function â€LST::CIterators::Iterator_Forward& LST::CIterators::Iterator_Forward::operator++()’: lst_iterators.h:77:7: error: â€m_pData’ was not declared in this scope ++m_pData;
- Everything works properly in VS2017, but gcc complains.
- As can be seen m_pData is a normal variable in Iterator_Base class, so why can't gcc see the base class?
- I'm using Centos 7.2 and gcc 6.3.
Any help is appreciated.
Br Waldemar
template <typename itemType> class CIterators
{
public: class Iterator_Base
{
//Constructor/Destructor
public: Iterator_Base( itemType* pData ) : m_pData( pData )
{
};
protected: itemType* m_pData;
//Operators
public: itemType& operator*()
{
//Value operator -> return reference.
return *m_pData;
};
public: bool operator!=( const Iterator_Base& iterator ) const
{
//Not equal operator -> compare if not at same pointer.
return ( m_pData != iterator.m_pData );
};
};
public: class Iterator_Forward : public Iterator_Base
{
//Constructor/Destructor
public: Iterator_Forward( itemType* pData ) : Iterator_Base( pData )
{
};
//Operators
public: Iterator_Forward& operator++()
{
//Increment operator -> go to next value (increase pointer).
++m_pData;
//Return reference.
return *this;
};
};
};
Edit: I still don't understand why gcc doesn't see or know about the base class, but Kerrek's solution works ok.
public: Iterator_Forward& operator++()
{
//Increment operator -> go to next value (increase pointer).
++this->m_pData;
//Return reference.
return *this;
};
Edit2: Also found the same issue at Derived template-class access to base-class member-data . Maybe a better solution then this-> is to define which variables are used from base class.
public: class Iterator_Forward : public Iterator_Base
{
protected: using Iterator_Base::m_pData;
//Constructor/Destructor
public: Iterator_Forward( itemType* pData ) : Iterator_Base( pData )
...