gpt4 book ai didi

c++ - 没有匹配函数来调用 'meetings::meetings()

转载 作者:行者123 更新时间:2023-11-30 01:53:12 24 4
gpt4 key购买 nike

编程新手,但当我尝试创建此链接列表时,我收到错误消息“没有匹配的函数调用‘meetings::meetings()’”已经经历了几次,但我只是没有看到它是什么导致问题。

 class meetings{

public:


void duplicatetest (string,memberlist *&head);
void menufn(memberlist *&head);
void meetinginfo( memberlist *&head,string);
string timestamp ( memberlist *&head,string);

memberlist *&head;
string UID;
string timestp;
meetings *timest;
meetings *link;
int meetnum;
string dt;

};

 void meetings::meetinginfo(memberlist *&head, string dt ){
string meetingNum;
memberlist *currptr;
meetings *meetptr , *nnmeet ,*meetcurr, *meethead;

meethead= NULL;

if (currptr->meetnum == 0 ) {
meethead = new meetings; // <<< Error appears here!
meetingNum = currptr->UID;
meethead->UID = meetingNum;
meethead->timestp = dt;
meetcurr=meethead;
system ("pause");
}
else {
nnmeet = new meetings;
meetcurr->link= nnmeet;
nnmeet->UID=currptr->UID;
nnmeet->timestp = dt;
}

cout << "Meeting number : ";

menufn(head);

}

using namespace std;

#include "memberlist.h"
#include "meeting.h"
int main(){
system("color f0");
memberlist *member,entermember;
meetings menu, *meet;

entermember.createlinklist(member);

menu.menufn(member);

system("pause");
return 0;
}//End of main

这是我从 session 类中提到的另一个类

 class memberlist  {

public:
void createlinklist (memberlist *&head);
void displaylist (memberlist *&head);
memberlist *link;
string name[2];
string UID;
int meetnum;


};

void memberlist::createlinklist (memberlist *&head)
{
ifstream fin;
memberlist *currptr , *nnptr;

head = NULL;


fin.open ("members.txt");


while (fin)
{
if(head==NULL)
{
head = new memberlist;

fin>>head->UID >> head->name[0] >> head->name[1];
head->meetnum = 0;
currptr = head;

}

nnptr = new memberlist;

currptr->link = nnptr;


fin>>nnptr->UID >> nnptr->name[0] >> nnptr->name[1];
nnptr->meetnum = 0;
currptr = nnptr;

}


currptr->link = NULL;
currptr = NULL;


displaylist(head);
}

void memberlist::displaylist (memberlist *&head)
{
//memberlist *meetptr;
cout << " Student information " << endl;
memberlist *currptr;
currptr = head;
//meetptr = meethead;



while (currptr->link!= NULL)
{
cout << setw(10) << left << currptr->UID << " " << currptr->name[0] <<" " <<
currptr->name[1] <<endl;
currptr= currptr->link;
}

}

最佳答案

问题是数据成员 head 被定义为引用。

memberlist *&head;

编译器无法生成默认构造函数,因为它不知道如何初始化引用。您必须自己定义构造函数。

根据C++标准

A defaulted default constructor for class X is defined as deleted if: — any non-static data member with no brace-or-equal-initializer is of reference type,

还要考虑到 referebces 只能在 ctor 初始化器中初始化。例如

meetings::meetings( memberlist * &ptr ) : head( ptr )
{
// possible some additional code
}

或者正如我在类定义中使用大括号或等于初始化器引用的引文中所说的那样。

关于c++ - 没有匹配函数来调用 'meetings::meetings(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23312515/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com