新手编程 望指点
# include "iostream.h"
# include "conio.h"
# include "stdio.h"
# include "string.h"
# define max 2
class Student
{public:
//构造函数
Student ()
{Name=new char[19+1];
Number=new char[9+1];
return ;
}
Student(const Student &other)//拷贝构造
{Name=other.Name;
Number=other.Number;
Sex=other.Sex;
Age=other.Age;
}
Set()//赋值
{
cout<<"please enter the name:";
cin>>Name;
cout<<"please enter the number:";
cin>>Number;
cout<<"please enter the sex:";
cin>>Sex;
cout<<"please enter the age:";
cin>>Age;
}
//析构
~Student()
{delete Name;
delete Number;
return ;
}
//返值函数
char * getname()
{return Name;}
char *getnumber()
{return Number;
}
char getsex()
{return Sex;
}
int getage()
{return Age;
}
protected:
char *Name;
char *Number;
char Sex;
int Age;
};
class StudentTable
{public:
StudentTable()//构造
{q=new struct Table[1];
h=q;
return ;
}
INStable()//插入
{p=new Table[1];
p->s.Set();
p->next=NULL;
while (h=h->next);
h->next=p;
h=q;
}
DELtable()//删除
{ char *number=new char[9+1];
cout<<"please enter the number:";
cin>>number;
while(!strcmp(h->s.getnumber(),number))h=h->next;
if(!h)cout<<"Error";
else
{p=h;
h=h->next;
delete p;
}
h=q;
return 1;
}
~StudentTable()//析构
{ while(h)
{ p=h;
h=h->next;
delete p;
}
}
protected:
struct Table
{Student s;
Table *next;
}*q,*p,*h;
};
int main()
{StudentTable Table;
Table.INStable();
Table.DELtable();
return 1;
}
为什么编译只是有警告(不知道为什么),但运行不了
问题点数:100、回复次数:4Top
1 楼jasmineily(学习中)回复于 2004-12-03 19:58:39 得分 20
h=h->next其中h未初始化,h->next访问的话就职segmen fault或XXX不能为read了Top
2 楼zxx110(新)回复于 2004-12-03 20:03:41 得分 0
是哪行的h=h->nextTop
3 楼hcj2002(流浪者·躬自厚而薄责于人 )回复于 2004-12-03 22:26:29 得分 80
构造函数和析构函数没有返回值,而其他的函数应指明返回类型。Top
4 楼zxx110(新)回复于 2004-12-06 14:38:45 得分 0
哦
谢了Top




