基本的に、対応するノードとその要素を出力しようとしています。しかし、エラーが発生しました。Error 1 error C2440: 'return' : cannot convert from 'DoublyLinkedListNode<Datatype> *' to 'int &'
インデックス関数の戻り値の型を変更するなど、いくつかのことを試しましたが、これまでのところ喜びはありませんでした。誰でもこれを修正するのを手伝ってもらえますか?
これが私のコードです:
//-------------------------------------------------------------------------------------------
// Name: Print.
// Description: Prints the elements from the list along with its index.
//-------------------------------------------------------------------------------------------
void Print(DoublyLinkedList<int>& p_list)
{
//Set up a new Iterator.
DoublyLinkedListIterator<int> itr = getIterator();
for(itr.Start(); itr.Valid(); itr.Forth())
{
cout <<"Index: "<<itr.Index() << "Element: " << itr.Item() << "\n";
}
cout << endl;
}
//-------------------------------------------------------------------------------------------
// Class: DoublyLinkedIterator.
//-------------------------------------------------------------------------------------------
template <class Datatype>
class DoublyLinkedListIterator
{
public:
//-------------------------------------------------------------------------------------------
// Member Vairables.
//-------------------------------------------------------------------------------------------
DoublyLinkedListNode<Datatype>* m_node;
DoublyLinkedList<Datatype>* m_list;
DoublyLinkedListIterator(DoublyLinkedList<Datatype>* p_list= 0, DoublyLinkedListNode<Datatype>* p_node= 0)
{
m_list= p_list;
m_node= p_node;
}
// ------------------------------------------------------------------
// Name: Start
// Description: Resets the iterator to the beginning of the list.
// Arguments: None.
// Return Value: None.
// ------------------------------------------------------------------
void Start()
{
if(m_list!= 0)
m_node= m_list -> m_head;
}
// ----------------------------------------------------------------
// Name: End
// Description: Resets the iterator to the end of the list
// Arguments: None.
// Return Value: None.
// ----------------------------------------------------------------
void End()
{
if(m_list!= 0)
m_node = m_list->m_tail;
}
// ----------------------------------------------------------------
// Name: Forth
// Description: Moves the iterator forward by one position
// Arguments: None.
// Return Value: None.
// ----------------------------------------------------------------
void Forth()
{
if(m_node!= 0)
m_node= m_node->m_next;
}
// ----------------------------------------------------------------
// Name: Back
// Description: Moves the iterator backward by one position.
// Arguments: None.
// Return Value: None.
// ----------------------------------------------------------------
void Back()
{
if(m_node!= 0)
m_node = m_node->m_prev;
}
// ----------------------------------------------------------------
// Name: Item
// Description: Gets the item that the iterator is pointing to.
// Arguments: None.
// Return Value: Reference to the data in the node.
// ----------------------------------------------------------------
Datatype& Item()
{
return m_node->m_data;
}
// ----------------------------------------------------------------
// Name: Index
// Description: Gets the index that the iterator is pointing to.
// Arguments: None.
// Return Value: Reference to the data in the node.
// ----------------------------------------------------------------
Datatype& Index()
{
return m_node;
}
// ----------------------------------------------------------------
// Name: Valid
// Description: Determines if the node is valid.
// Arguments: None.
// Return Value: true if valid
// ----------------------------------------------------------------
bool Valid()
{
return (m_node!= 0);
}