我刚开始学习C++
(来自Java
)并且在做任何事情时都遇到了一些严重的问题:P 目前,我正在尝试制作一个链接列表,但一定是在做一些愚蠢的事情,因为我不断得到“应该忽略的无效值” " 编译错误(我已将它标记在下面抛出它的位置)。如果有人可以帮助我解决我做错的事情,我将非常感激:)
此外,我不习惯选择通过引用、地址或值传递以及一般的内存管理(目前我的所有节点和数据都声明在堆上)。如果有人对我有任何一般性建议,我也不会抱怨:P
LinkedListNode.cpp中的关键代码
LinkedListNode::LinkedListNode()
{
//set next and prev to null
pData=0; //data needs to be a pointer so we can set it to null for
//for the tail and head.
pNext=0;
pPrev=0;
}
/*
* Sets the 'next' pointer to the memory address of the inputed reference.
*/
void LinkedListNode::SetNext(LinkedListNode& _next)
{
pNext=&_next;
}
/*
* Sets the 'prev' pointer to the memory address of the inputed reference.
*/
void LinkedListNode::SetPrev(LinkedListNode& _prev)
{
pPrev=&_prev;
}
//rest of class
LinkedList.cpp 中的关键代码
#include "LinkedList.h"
LinkedList::LinkedList()
{
// Set head and tail of linked list.
pHead = new LinkedListNode();
pTail = new LinkedListNode();
/*
* THIS IS WHERE THE ERRORS ARE.
*/
*pHead->SetNext(*pTail);
*pTail->SetPrev(*pHead);
}
//rest of class