| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 199 人关注过本帖
标题:求助:程序出错
只看楼主 加入收藏
jackwinki
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-8-25
收藏
 问题点数:0 回复次数:0 
求助:程序出错

在写完这个程序后编译和链接都是对的,可为什么运行的时候就出错了啊(下面是截图),百思不得其解,请各位高手帮忙
注:在屏蔽了①②两句后就可以正常运行了,估计是复制构造函数出了问题,但又没发现什么问题,实在想不出来了


#include"iostream"
#include"string"
using namespace std;
class people
{public:
people()
{cout<<"constructing a people..."<<endl;
}

people(const people &p)
{cout<<"copy na people"<<endl;
name=new char[strlen(p.name)];
strcpy(name,p.name);
id=p.id;
sex=p.sex;
}

~people()
{ cout<<"destructing a people..."<<endl;
delete []name;
}

void getname(char *NAME)
{ int a;
a=strlen(NAME);
name=new char[a+1];
strcpy(name,NAME);
cout<<"get a name"<<endl;
cout<<"the name is "<<name<<endl;
}

void getID(int ID)
{ id=ID;
cout<<"get a ID"<<endl;
}

void getsex(int a)
{ sex=a;
cout<<"get a sex"<<endl;
}

protected:
char *name;
int id;
int sex;
};


class student:public people
{ public:
student():people()
{
cout<<"constructing a student..."<<endl;
}

student(const student &stu):people(stu)
{ cout<<"copy a student"<<endl;
course=new char[strlen(stu.course)+1];
strcpy(course,stu.course);
}

void getcourse(char *c)
{course=new char[strlen(c)+1];
strcpy(course,c);
cout<<"get a course"<<endl;
cout<<"the course is "<<course<<endl;
}

void rename()
{ strcpy(name,"jack");
}

void display()
{ cout<<"the name is"<<name<<endl;
}

~student()
{ delete []course;
cout<<"destructing a student..."<<endl;
}

protected:
char *course;
};

void main()
{ student s1;
s1.getname("winki");
s1.getcourse("computer");
student s2(s1);//①
s1.rename();
s1.display();
s2.display();②
}


附件: 游客没有浏览附件的权限,请 登录注册
2007-10-27 02:59
快速回复:求助:程序出错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027834 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved