vc中如编译器告诉你你的类重定义了,那是什么错误了?

有如下代码,各位仁兄帮忙看看.我编译时它提出类peopl从定义了。#include<iostream.h>classpeople{longintid;char*name;... 有如下代码,各位仁兄帮忙看看.我编译时它提出类peopl从定义了。
#include<iostream.h>
class people{
long int id;
char * name;
char * sex;
char * addr;
int * birth;
people * next,* top,* rear,* head;

public:
people(){
id=0;
name=NULL;
sex=NULL;
addr=NULL;
birth=NULL;
head=NULL;
}
void hinput(people * p);
people * create();
people * search(long int idl);
void show(people * q);
void chart(people * q);
void cancel(people *p);
~people(){ people * p;
if(top!=NULL)
p=top;
while(p!=NULL)
{
delete p;
p=p->next;
}
};
void people::hinput(people * p)
{
cout<<"please input id"<<endl;
cin>>p->id;
cout<<"please input name"<<endl;
cin>>p->name;
cout<<"please input sex"<<endl;
cin>>p->sex;
cout<<"please input addr"<<endl;
cin>>p->addr;
cout<<"please input birth"<<endl;
cin>>p->birth;

}
people * people::create()
{
people * p,* q;
char rtn;
cout<<"do you input continue? Y/N"<<endl;
rtn=getchar();
while(rtn=Y)
{
p=new people;
q->next=p;
hinput(p);
if(head!=NULL)
head=p;
q=p;
else
q=p;
cout<<"will you input continue? Y/N"<<endl;
rtn=getchar();
}
rear=p;
return head;
}
people * people::search(idl)
{ people * p=head;
while(idl!==p->id)
{
p=p->next;
}

return p;
}
void people::show(people * p){
cout<<p->id<<endl<<p->addr<<endl<<p->birth
<<endl<<p->sex<<endl<<p->name<<endl;
}
void people::chart(people * q){
people *p;
p=new people;
hinput(p);
p->next=q->next->next;
q.next=p;
cout<<"chart sucess! "<<endl;
}
void people::cancel(people * p)
{ people *q;
q=p->next->next;
delete p->next;
p->next=q;
cout<<"cancel sucess! "<<endl;
}

#include<iostream.h>
#include"people.hpp"

people wek;
void main()
{void func();

wek.create();
func();

}
void func(){ people * p;
long int idl;
cout<<"please input your id"<<endl;
cin>>idl;
p=wek.search(idl);
wek.show(p);
}
展开
 我来答
爽口还明快灬彩旗L
2009-03-31 · TA获得超过322个赞
知道小有建树答主
回答量:196
采纳率:0%
帮助的人:273万
展开全部
//下面点出了你说的错误的原因,不过整个程序还是不能运行,貌似你在create函数中对指针进行写入操作?

#include<iostream.h>
#include <stdio.h>

class people{
long int id;
char * name;
char * sex;
char * addr;
int birth;
people * next,* top,* rear,* head;

public:
people(){
id=0;
name=NULL;
sex=NULL;
addr=NULL;
birth=NULL;
head=NULL;
}
void hinput(people * p);
people * create();
people * search(long int idl);
void show(people * q);
void chart(people * q);
void cancel(people *p);
~people(){ people * p;
if(top!=NULL)
p=top;
while(p!=NULL)
{
delete p;
p=p->next;
}
}/////////////////////////函数重定义是因为缺少这个括号
};
void people::hinput(people * p)
{
cout<<"please input id"<<endl;
cin>>p->id;
cout<<"please input name"<<endl;
cin>>p->name;
cout<<"please input sex"<<endl;
cin>>p->sex;
cout<<"please input addr"<<endl;
cin>>p->addr;
cout<<"please input birth"<<endl;
cin>>p->birth;

}
people * people::create()
{
people * p,* q;
char rtn;
cout<<"do you input continue? Y/N"<<endl;
rtn=getchar();
while(rtn='Y') //////////这里应该是'Y',不过我不会使用Y/N,这里会出错
{
p=new people;
q->next=p;
hinput(p);
if(head!=NULL)
{
head=p;
q=p;
}
else
q=p;
cout<<"will you input continue? Y/N"<<endl;
rtn=getchar();
}
rear=p;
return head;
}
people * people::search(long int idl)
{ people * p=head;
while(idl!=p->id)
{
p=p->next;
}

return p;
}
void people::show(people * p){
cout<<p->id<<endl<<p->addr<<endl<<p->birth
<<endl<<p->sex<<endl<<p->name<<endl;
}
void people::chart(people * q){
people *p;
p=new people;
hinput(p);
p->next=q->next->next;
q->next=p;
cout<<"chart sucess! "<<endl;
}
void people::cancel(people * p)
{ people *q;
q=p->next->next;
delete p->next;
p->next=q;
cout<<"cancel sucess! "<<endl;
}

#include<iostream.h>
#include"people.hpp"

people wek;

void main()
{
void func();

wek.create();
func();

}
void func(){ people * p;
long int idl;
cout<<"please input your id"<<endl;
cin>>idl;
p=wek.search(idl);
wek.show(p);
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式