每当我使用showInfo函数时: 编辑:它运行一次,但第二次打破。
void showInfo(){
node * temp = head;
while (temp){
temp->showInfo();
temp = temp->getNext();
}
}
with temp-> showInfo();指着:
void showInfo(){
cout << data << endl;
}
我尝试访问NULL时遇到0x0000005错误。我假设它是我的appendNode函数:
void appendNode(node * n){
if (head == nullptr){
head = n;
}
else{
node * iter = head;
while (iter->getNext()){
iter = iter->getNext();
}
iter->setNext(n);
}
size++;
}
节点分配如下:
int main(){
char * data1 = "g";
char * data2 = "b";
char * data3 = "k";
linkedList * list = new linkedList();
node * g = new node();
g->setData(data1);
list->setHead(g);
node * b = new node();
list->appendNode(b);
node * k = new node();
list->appendNode(k);
list->showInfo();
return 0;
}
赞赏任何提示和方向。
编辑:单步表示它在iosfwd中断开。它打破的代码是:
static size_t __CLRCALL_OR_CDECL length(const _Elem *_First)
{ // find length of null-terminated string
return (*_First == 0 ? 0
: _CSTD strlen(_First));
}