求大神帮忙解决
#include<iostream.h>#include<string.h>class student{ private: int x; char y[16]; float z; public: student(int a,char b[16],float c) { x=a; strcpy(y,b); z=c; cout<<"调用学生类构造函数"<<endl; } void show() {cout<<"学号"<<x<<' '<<"姓名"<<y<<' '<<"分数"<<z<<endl;} ~student() {cout<<"调用学生析类构函数"<<endl;}};class teacher{ private: int q; char w[16]; float e; public: teacher(int u,char i[16],float o) { q=u; strcpy(w,i); e=o; cout<<"调用教师类构造函数"<<endl; } void show() {cout<<"职工号"<<q<<' '<<"姓名"<<w<<' '<<"工资"<<e<<endl;} ~teacher() {cout<<"调用教师类析构函数"<<endl;}};class stu_tea:public student,public teacher{ public: stu_tea(int a,char b[16],float c ,int u,char i[16],float o) :student(a,b[16],c),teacher(u,i[16],o) { strcpy(y,b) strcpy(w,i);} void show() {cout<<"职工号信息"<<endl;} ~stu_tea() {cout<<"调用助教类析构函数"<<endl;}};void main(){ stu_tea t(10001,"abc",88,10002,"chi",4000);t.student::show();t.teacher::show ();t.stu_tea::show ();t.student::~student ();t.teacher::~teacher ();t.stu_tea::~stu_tea ();}
1。下次提问一定要排好版的
2。你的问题主要出在
public:
stu_tea(int a,char b[16],float c ,int u,char i[16],float o) :student(a,b[16],c),teacher(u,i[16],o)
{ strcpy(y,b) strcpy(w,i);}
其中又有多个问题
1)student构造的第二个参数是数组,你的b[16]是数组的元素非数组
2)同样teacher的i[16]也是
3) strcpy(y,b) strcpy(w,i);两个函数间少分号了
4) 即使改为strcpy(y,b);strcpy(w,i);,你的y,w都是父类的私有成员,你的继承类是不能访问的,也你的初始化已完成对y,w的赋值了啊,所以是画蛇添足了
直接改为
stu_tea(int a,char b[16],float c ,int u,char i[16],float o) :student(a,b,c),teacher(u,i,o) //修改
{
// strcpy(y,b) ; //删除
// strcpy(w,i); //删除
}
3。你的
#include<iostream.h>
及
void main()
这样的写法是非ISO C++标准的写法,只能用于上世纪淘汰的vc++6.0(你的教材太老了)
标准的是
#include<iostream>
#include<string.h>
using namespace std;
...
int main()
{
...
return 0;
}
程序的最终结果为