Hello Rob,
Sorry to distrub you again.
But does your solution induce that class "Iterator" can not be instantiated
when instantiating class "BicircularList"?
Now I got this message(BTW: my compiler is VC++ 6):
unresolved external symbol "public: int * __thiscall
BicircularList<int>::Iterator::Next(void)"
(?Next@Iterator@?$BicircularList@H@@QAEPAHXZ)
Here is my unabridged class definition conforming your advise:
// code begin
template<class T> class BicircularList
{
public:
class Iterator;
private:
class ChainNode
{
friend class BicircularList<T>; // BTW: Is the keyword class really
necessary?
friend class Iterator;
private:
T m_tData;
ChainNode *m_pNext;
ChainNode *m_pPrev;
};
public:
class Iterator
{
public:
T* Init(const BicircularList<T>& list);
T* Next();
private:
ChainNode *m_pHead;
ChainNode *m_pCur;
};
friend class Iterator;
public:
BicircularList();
~BicircularList();
// ... methods omitted
private:
ChainNode m_tNode;
};
// end of code
Best Regards
Roy Yao
"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> wrote in message
news:<Xn**********************************@195.129 .110.130>...
Roy Yao wrote in news:bh***********@mail.cn99.com:
Why the following code let my compiler complain an overloaded function
Init()?
// code begin
template<class T> class BicircularList
{
// no template <class T>
class Iterator;
// no template <class T> again
class ChainNode
{
// class is required here
friend class Iterator;
// ...
};
// ...
public:
// no template <class T>
class Iterator
{
public:
T* Init(const BicircularList<T>& list);
T* Next();
private:
// removed a <T>
ChainNode *m_pHead;
ChainNode *m_pCur;
};
// ...
}; // don't forget this!
// removed a <T> after Iterator
template<class T>
T* BicircularList<T>::Iterator::Init(const BicircularList<T>& list)
{
m_pHead = const_cast<ChainNode<T> *> (&list.m_tNode);
m_pCur = m_pHead->m_pNext;
return (m_pCur!=m_pHead ? &m_pCur->m_tData : 0);
}
Here is the error message:
error C2244: 'BicircularList<T>::Iterator<T>::Init' : unable to resolve
function overload
HTH
Rob.
--
http://www.victim-prime.dsl.pipex.com/