呼叫'meetings :: meetings()没有匹配功能

时间:2014-04-26 14:50:33

标签: c++

编程新手,但是当我尝试创建此链接列表时,我收到一个错误'没有匹配函数来调用'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

这是我从会议课程中引用的另一个课程

 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; 
 }

 }

1 个答案:

答案 0 :(得分:4)

问题是数据成员头被定义为参考。

memberlist *&head;

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

根据C ++标准

  

如果符合以下情况,则将类X的默认默认构造函数定义为已删除:    - 任何没有大括号或等于初始化程序的非静态数据成员   参考类型,

还要考虑到只能在ctor初始化程序中初始化引用。例如

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

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