【发布时间】:2021-02-21 14:42:15
【问题描述】:
我不断收到错误消息 undefined symbol insert(*Friend)。任何人都可以识别并解释错误吗?我知道它指的是它找不到它但我无法确定问题所在,请帮助。我正在开发一个使用链表保存朋友信息数据库的程序。因此,我试图在程序启动后将头节点初始化为null,并检查第一个插入是否此头是null,如果是这种情况,则将指针分配给新节点。
#include <iostream>
using namespace std;
// MARK: Friend Struct
struct Friend {
string last;
string first;
int yob;
int mob;
int dob;
string sex;
struct Friend* next;
};
Friend* head = NULL;
void insert(struct Friend* head);
void getData();
// MARK: Main Method
int main(int argc, const char* argv[])
{
insert(head);
return 0;
}
// MARK: Get Data Method
void getData(string& f, string& l, string& s, int& y, int& m, int& d)
{
cout << "Please type friend's first name: " << endl;
cin >> f;
cout << "Please type friend's last name: " << endl;
cin >> l;
cout << "Please type friend's year of birth (yyyy): " << endl;
cin >> y;
cout << "Please type friend's month of birth (mm): " << endl;
cin >> m;
cout << "Please type friend's day of birth (dd): " << endl;
cin >> d;
cout << "Please type friend's sex (f/m): " << endl;
cin >> s;
}
// MARK: Insert new Friend Method
void insert(struct Friend** head)
{
string f, l, s;
int y = 0, m = 0, d = 0;
getData(f, l, s, y, m, d);
Friend* tmp = new Friend;
tmp->first = f;
tmp->last = l;
tmp->yob = y;
tmp->mob = m;
tmp->dob = d;
tmp->sex = s;
tmp->next = NULL;
if (*head == NULL) {
*head = tmp;
}
};
【问题讨论】:
标签: c++ pointers struct linked-list