1

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;

  1. Everything works properly in VS2017, but gcc complains.
  2. As can be seen m_pData is a normal variable in Iterator_Base class, so why can't gcc see the base class?
  3. 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 )
        ...
Community
  • 1
  • 1
Waldemar
  • 171
  • 9
  • 2
    Is gcc really writing these strange characters or is it just a misprint in a question text? – alexeykuzmin0 Apr 04 '17 at 09:21
  • 9
    Stop annotating everything with an access specifier. It's not Java. – molbdnilo Apr 04 '17 at 09:21
  • Looks like `m_pData` is dependent, so it cannot be used unqualified during the first phase. Say `this->m_pData` instead. MSVC does not implement two-phase lookup correctly as far as I know. – Kerrek SB Apr 04 '17 at 09:22
  • 1
    The error in your title is completely different from the error in your body. – Lightness Races in Orbit Apr 04 '17 at 11:21
  • Alex: I assume it's a codepage issue when working from Wins to Linux through shell... I'm so used to it, that I don't see it anymore. – Waldemar Apr 04 '17 at 11:48
  • 2
    Molbdnilo: As I'm programing for 30 years, have seen a lot of code which ranged from beauty to pure shit and have worked with multiple languages. So I have taken best from every one and created my own coding style which is much, much, much more descriptive, transparent and beautiful then other (for example lately I'm also working with Qt library which is pure horror to me, so I've finally decided that I'll ditch it and create my own). – Waldemar Apr 04 '17 at 11:50
  • Kerrek: Thanks for the idea, but it still doesn't work... I'll dig deeper. – Waldemar Apr 04 '17 at 12:01
  • BoundaryImposition: Thanks for the notice... have fix it. – Waldemar Apr 04 '17 at 12:02
  • Kerrek: After changing some other derived classes your this-> idea worked beautifully. Thanks. – Waldemar Apr 04 '17 at 14:47
  • Alex: Changed the codepage to UTF8 and now there is ‘ characters instead of garbage. – Waldemar Apr 05 '17 at 08:32

0 Answers0