void listord::stmp()
{
nodeL *aux=head;
cout<<"STMP"<<endl;
while (aux)
{
cout<<aux->getData();
aux=aux->getNext();
}
cout<<endl;
return;
}
我不明白为什么这只是列出打印代码循环。我知道这可能是由于指针错误导致的,但我不知道如何解决。
class nodeL{
private:
int data;
nodeL *next;
public:
nodeL();
nodeL(int d);
nodeL(int d,nodeL *n);
int getData();
nodoL *getNext();
void setData(int d);
void setNext(nodeL *n);
};
这是nodeL类,GetNext()
只是下一个返回,没什么。
答案 0 :(得分:0)
您想在构造函数中设置next = nullptr
。另外,您还想从getNext函数返回*&
,如下所示:
nodeL *& getNext();
这两件事应该可以解决您的问题。