新手求助:error C2679: binary '=' : no operator defined which takes a right-hand oper

sbysby00 2013-04-08 04:36:27
运行时候出现这个错误:应该怎么改?为什么DelQ出队列中写上x=-1;返回值就出现错误?
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)
#include<iostream>
#include<iomanip>
#include<string>
//#include<conio.h>
#define MAXSIZE 20
using namespace std;
struct ElemType
{
char name[10];
int num;
};
struct quenode
{
ElemType data;
quenode *next;
};

class LsQueue
{
private:
quenode *front,*rear;
public:
LsQueue();
~LsQueue();
int IsEmpty();
void Display();
void AddQ(ElemType x);
ElemType DelQ();

};

LsQueue::LsQueue()
{
quenode *p;
p=new quenode;
p->next=NULL;
front=rear=p;
}

void LsQueue::AddQ(ElemType x)
{
quenode *s;
s=new quenode;
s->data=x;
s->next=NULL;
rear->next=s;
rear=s;
}

ElemType LsQueue::DelQ()
{
ElemType x;quenode *p;

if(front==rear)
{cout<<"\n队列为空!"<<endl;x=-1; }!!!为什么这里写上x=-1会提示错误!???

else{
p=front->next;
front->next=p->next;
if(p->next==NULL)rear=front;
x=p->data;
delete p;
}
return x;
}

int LsQueue::IsEmpty()
{
if(front==rear)return 1;
else return 0;
}

LsQueue::~LsQueue()
{
quenode *p;
p=front->next;
while(p!=rear)
{
front->next=p->next;
delete p;
p=front->next;
}
delete rear;
delete front;
rear=front=NULL;
}

void LsQueue::Display()
{
quenode *p;
p=front->next;
while(p!=NULL)
{
cout<<setw(5)<<p->data.num;
cout<<setw(10)<<p->data.name<<endl;
p=p->next;
}
cout<<"OUT End!"<<endl;

}

int main()
{
int i,n=10;
ElemType e,x;
LsQueue Q;
for(i=1;i<=n;i++)
{
x.num=i;
cout<<"\ni="<<i<<"输入姓名:";
cin>>x.name;
Q.AddQ(x);
}
Q.Display();
...全文
749 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
u010212719 2013-04-08
  • 打赏
  • 举报
回复
改成x.num=-1
landiya 2013-04-08
  • 打赏
  • 举报
回复
这里x是ElemType型的变量,你写成x.num=-1就不会错了

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧