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 @?$BicircularLi st@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.RE MOVE.co.uk> wrote in message
news:<Xn******* *************** ************@19 5.129.110.130>. ..
Roy Yao wrote in news:bh******** ***@mail.cn99.c om:
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::I nit(const BicircularList< T>& list)
{
m_pHead = const_cast<Chai nNode<T> *> (&list.m_tNode) ;
m_pCur = m_pHead->m_pNext;
return (m_pCur!=m_pHea d ? &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/