炸鸡叔GUS 2014-12-21 05:29 采纳率: 33.3%
浏览 1426

求解这个程序为什么运行不了

//头文件定义结构体和类
#ifndef tongxunlu_h
#define tongxunlu_h

struct Bir
{
int year,month,day;
};

struct Student
{
char name;
char sex;
char address;
int code;
int age;
int number;
int QQ;
char wechat;
Bir birthady;
};

struct Node
{
Student data;
Node *next;
};

class StudentList
{
public:
StudentList();
StudentList(Student a[],int n);
//~StudentList();
int Length();
Student Get(int i);
int Locate(Student x);
void Insert(int i,Student x);
Student Delete(int i);
void PrintList();
private:
Node *first;
};

#endif
//定义成员函数
#include
using namespace std;
#include "tongxunlu.h"

StudentList::StudentList()
{
first = new Node;
first->next=NULL;//只有一个头结点,没有元素
}

StudentList::StudentList(Student a[],int n)
{
first=new Node;//头结点
first->next=NULL;
for(int i=0;i {
Node *s=new Node;s->data=a[i];//头插法
s->next=first->next;first->next=s;
}
}

int StudentList::Length()
{
Node *p=first->next;//p初始化为指向首元结点
int count=0;
while(p!=NULL)
{
p=p->next;
count++;
}
return count;
}

Student StudentList::Get(int i)
{
Node *p=first->next;
int count=1;
while(p!=NULL&&count {
p=p->next;
count++;
}
if(p==NULL)throw"位置";
else return p->data;
}

int StudentList::Locate(Student x)
{
Node *p=first->next;
int count=1;
while(p!=NULL)
{
if(p->data==x)
return count;
p=p->next;
count++;
}
return 0;
}

void StudentList::Insert(int i,Student x)
{
Node *p=first;
int count=0;
while(p!=NULL&&count {
p=p->next;
count++;
}
if(p==NULL)throw"位置";
else
{
s=new Node;s->data=x;
s->next=p->next;p->next=s;
}
}

Student StudentList::Delete(int i)
{
Node *p=first;
int count=0;
while(p!=NULL&&count {
p=p->next;
count++;
}
if(p==NULL||p->next==NULL)//结点p不存在或p的后继结点不存在
throw"位置";
else
{
Node *q=p->next;
Student x=q->data;//暂存被删结点
p->next=q->next;//摘链
delete q;
return x;
}
}

void StudentList::PrintList()
{
Node *p=first->next;
while(p!=NULL)
{
cout<data;
p=p->next;
}
}
//主函数
#include
using namespace std;
#include "tongxunlu.cpp"

int main()
{
Student a[5];
int i;
cout<<"请输入5位学生的信息:"
for(i=0;i cin>>a[i];
StudentList stu(a,5);
stu.PrintList();
return 0;
}
运行发现错误是could not deduce template arguement for'const class std::allocator<_Ty>& from 'struct Student'
看不懂是什么意思,求教!

  • 写回答

1条回答 默认 最新

  • 91program 博客专家认证 2014-12-21 07:07
    关注

    这个应该是编译错误,不是运行时错误吧。
    参数类型不匹配。是那一行代码,你应该知道吧,两个数据类型:std::allocator<_Ty>& 和 'struct Student' 之间不能进行隐式转换。

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大