this 是 nullptr。
是执行下面这个函数出的问题
void Worker::registration(Worker * head)
{
while (head->next != NULL)
{
head = head->next;
}
Worker*node = new Worker;
head->next = node;
node = NULL;
cout << "输入姓名:";
cin >> node->Name;
cout << "输入性别:";
cin >> node->sex;
cout << "输入编号:";
cin >> node->Number;
cout << "输入电话:";
cin >> node->Phone;
cout << "输入年龄:";
cin >> node->age;
}
1 个解决方案
#1
Worker*node = new Worker;
head->next = node;
node = NULL; // 这里设置成了null
cout << "输入姓名:";
cin >> node->Name; // 这里又开始用了
cout << "输入性别:";
#1
Worker*node = new Worker;
head->next = node;
node = NULL; // 这里设置成了null
cout << "输入姓名:";
cin >> node->Name; // 这里又开始用了
cout << "输入性别:";