当我尝试传递链表的头指针时,我不断收到错误消息

     2023-02-21     67

关键词:

【中文标题】当我尝试传递链表的头指针时,我不断收到错误消息【英文标题】:I keep getting an error when I try to pass the head pointer of the linked list 【发布时间】: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;
    
;

【问题讨论】:

【参考方案1】:

你声明了void insert(struct Friend* head);(只有一颗星),但只定义了void insert(struct Friend** head)(有两颗星)。它们是不同的功能。

似乎应该将声明更正为两颗星(与定义匹配)并且在调用时应该传递&amp;head 而不是head

【讨论】:

【参考方案2】:

您将 (Friend*)head 传递给 insert(Friend **head),这是不正确的。 将呼叫更改为insert(&amp;head);

【讨论】:

当我尝试输入 phpunit 时,我不断收到此错误

】当我尝试输入phpunit时,我不断收到此错误【英文标题】:IkeepgettingthiserrorwhenItryinputphpunit【发布时间】:2016-05-0521:57:48【问题描述】:当我尝试使用phpunit时,我在phpStorm的命令行中不断收到此错误。谁可以给我解释一下这个?... 查看详情

尝试将共享按钮添加到 iPad 代码时,我不断收到错误消息

】尝试将共享按钮添加到iPad代码时,我不断收到错误消息【英文标题】:IkeepgettinganerrorwhentryingtoaddsharebuttontoiPadcode【发布时间】:2016-07-2213:17:14【问题描述】:我在调用代码时不断收到popovercontroller错误,这是我的代码:-(IBActi... 查看详情

当我尝试从双向链表中删除最后一个元素时,为啥会收到“信号 SIGSEGV,分段错误”?

】当我尝试从双向链表中删除最后一个元素时,为啥会收到“信号SIGSEGV,分段错误”?【英文标题】:WhydoIreceivea"signalSIGSEGV,segmentationfault"whenItrytodeletelastelementsfromdoublylinkedlist?当我尝试从双向链表中删除最后一个元素时... 查看详情

当我尝试使用 REST 保证解析 XML 响应时收到错误消息

】当我尝试使用REST保证解析XML响应时收到错误消息【英文标题】:IgetanerrormessagewhenitrytoparseanXMLresponseusingRESTassured【发布时间】:2022-01-0503:14:09【问题描述】:我正在使用这个简单的函数来获取并打印出XML响应中的值:@Testvoidval... 查看详情

尝试在 Nuxt 中将数据从组件传递到页面时出现错误消息

...据库中获取数据,并希望在我创建的页面中显示该数据。当我将组件嵌入页面时,我不断收到错误消息:属性或方法“provinces”未在实例上定义,但 查看详情

当我尝试在我的终端上运行代码时,我不断收到“ModuleNotFound”错误,即使我安装了它

】当我尝试在我的终端上运行代码时,我不断收到“ModuleNotFound”错误,即使我安装了它【英文标题】:Ikeepgetting"ModuleNotFound"errorwhenitrytoruncodeonmyterminaleventhoughiinstalledit【发布时间】:2021-12-0715:46:19【问题描述】:我与:... 查看详情

使用记录的 ghostscript 语法时,在 ghostscript 中不断收到错误消息

...题描述】:我是ghostscript的新手,我不知道语法。每当我尝试最简单的命令时,例如-h或-?我收到一个错误,我尝试了各种组合。GP 查看详情

当我尝试上传包含大约 2000 条记录的 csv 文件时,我一直收到此错误消息

】当我尝试上传包含大约2000条记录的csv文件时,我一直收到此错误消息【英文标题】:IKeepReceivingthiserrormessagewhenitryuploadingacsvfilethathasroundabout2000records【发布时间】:2018-03-3004:14:40【问题描述】:/*ServiceUnavailableTheserveristemporarily... 查看详情

在 My SQL 中不断收到外键约束失败消息

...据插入表Bookratings,但我不断收到此错误消息。这是因为当我尝试插入时,它会在Bookratings表中创建重复项,这是PRIMARY键约束所不允许的?MySQL错误1452-无法添加或更新子行:外键约 查看详情

当我或其他用户尝试使用 OAuth2 进行授权时,我不断收到需要验证我的应用程序的错误。那是啥意思?

】当我或其他用户尝试使用OAuth2进行授权时,我不断收到需要验证我的应用程序的错误。那是啥意思?【英文标题】:IkeepgettinganerrorthatmyappneedstobeverifiedwheneitherIoranotherusertrytoauthorizewithOAuth2.Whatdoesthatmean?当我或其他用户尝试使用... 查看详情

(Django)当我尝试将夹具文件加载到我的数据库中时,我不断收到字段冲突错误

】(Django)当我尝试将夹具文件加载到我的数据库中时,我不断收到字段冲突错误【英文标题】:(Django)WhenItrytoloadfixturefileintomydatabase,Ikeepgettingfield***error【发布时间】:2021-04-2406:46:04【问题描述】:当我尝试将夹具数据加载到... 查看详情

运行此代码时不断收到此错误

...iscode【发布时间】:2020-10-0315:44:11【问题描述】:我正在尝试创建验证通道,用户将在其中使用反应验证自己。我尝试从验证通道获取消息并尝试执行此代码:constmReaction=newDiscord.MessageReaction();constmessage=mReaction.message;const 查看详情

为啥我在尝试创建此表时不断收到外键错误? [复制]

...描述】:我正在尝试为数据库创建表。一切都很好,除了当我尝试创建最后一个连接表时,它一直给我一个外键错误“使用外键约束创建表\' 查看详情

尝试将 Flask 应用程序部署到 AWS Elastic Beanstalk 时,我不断收到“ModuleNotFoundError: No module named 'app'”错误消息

】尝试将Flask应用程序部署到AWSElasticBeanstalk时,我不断收到“ModuleNotFoundError:Nomodulenamed\\\'app\\\'”错误消息【英文标题】:WhentryingtodeployaFlaskapptoAWSElasticBeanstalk,Ikeepgettingthe"ModuleNotFoundError:Nomodulenamed\'app\'"error 查看详情

当我将新单元格添加到集合视图时,我不断收到布局错误

】当我将新单元格添加到集合视图时,我不断收到布局错误【英文标题】:IkeeponreceivingalayouterrorwhenIaddanewcelltoacollectionview【发布时间】:2018-01-2516:50:02【问题描述】:我正在尝试将数据从一个视图控制器添加到集合视图控制器... 查看详情

尝试绘制堆积条形图时收到形状不匹配错误消息

】尝试绘制堆积条形图时收到形状不匹配错误消息【英文标题】:Gettingashapemismatcherrormessagewhentryingtoplotastackedbarchart【发布时间】:2019-06-0812:36:52【问题描述】:我正在尝试从我的数据创建堆积条形图并不断收到错误消息ValueError... 查看详情

尝试将 python 字典列表转换为 SQLite 表时,我不断收到错误消息?

】尝试将python字典列表转换为SQLite表时,我不断收到错误消息?【英文标题】:WhentryingtoconvertalistofpythondictionariesintoaSQLitetableIkeepgettinganerror?【发布时间】:2022-01-0109:51:19【问题描述】:我正在尝试使用以下代码将python字典列表... 查看详情

当我启动下面的代码时,我不断收到此错误

】当我启动下面的代码时,我不断收到此错误【英文标题】:ikeepgettingthiserrorwhenistartthecodebelow【发布时间】:2021-08-1917:43:29【问题描述】:C:\\Users\\georg\\Desktop\\reactapp>npmstartreactapp@1.0.0开始webpack-dev-server--hot节点:内部/模块/cjs... 查看详情