有人可以解释为什么gcc会抛出:
lst_iterators.h:在成员函数中 - LST :: CIterators :: Iterator_Forward& LST :: CIterators :: Iterator_Forward ::操作++()A€™: lst_iterators.h:77:7:错误:“m_pData”未在此范围内声明 ++ m_pData;
感谢任何帮助。
溴 瓦尔德马
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;
};
};
};
编辑: 我仍然不明白为什么gcc没有看到或知道基类,但Kerrek的解决方案工作正常。
public: Iterator_Forward& operator++()
{
//Increment operator -> go to next value (increase pointer).
++this->m_pData;
//Return reference.
return *this;
};
EDIT2: 在Derived template-class access to base-class member-data也发现了同样的问题。也许这是一个更好的解决方案 - &gt;是定义从基类使用哪些变量。
public: class Iterator_Forward : public Iterator_Base
{
protected: using Iterator_Base::m_pData;
//Constructor/Destructor
public: Iterator_Forward( itemType* pData ) : Iterator_Base( pData )
...