这个类的继承性的题错在哪了呢?
原题:涉及父亲类Father,母亲类Mother,子女类Child,其主要数据成员是姓名,年龄和民族,子女继承了父亲的姓,母亲的民族。声名一个子女对象,并输出子女及其父母的姓名和民族信息。
这个是存放类的头文件:
#include <iostream.h>
#include <string.h>
class CFather
{protected :
char family_name[20],given_name[20];
int age;
char nation[20];
public:
CFather (char *px,char *py,int a,char *pz)
{strcpy(family_name,px);
strcpy(given_name,py);
age=a;
strcpy(nation,pz);
cout<<"父亲:"<<endl<<"姓:"<<family_name<<endl<<"名:"<<given_name<<endl<<"年龄:"<<age<<endl<<"民族:"<<nation<<endl;
}
};
class CMother
{protected :
char family_name[20],given_name[20];
int age;
char nation[20];
public:
CMother(char *px1,char *py1,int a1,char *pz1)
{strcpy(family_name,px1);
strcpy(given_name,py1);
age=a1;
strcpy(nation,pz1);
cout<<"母亲"<<endl<<"姓:"<<family_name<<endl<<"名:"<<given_name<<endl<<"年龄:"<<age<<endl<<"民族:"<<nation<<endl;
}
};
class CChild:public CFather,public CMother
{ protected :
char given_name1[20];
public:
CChild (char *p,char *px,char *py,int a,char *pz,char *px1,char *py1,int a1,char *pz1):CFather(px,py,a,pz),CMother(px1,py1,a1,pz1)
{strcpy(given_name1,p);}
};
这个是存放主函数的源文件:
#include "3 66.h"
void main()
{
CChild c("统","赵","云",44,"汉","貂","禅",40,"苗");
cout<<"子女:"<<endl<<"姓:"<<CFather ::family_name<<endl<<"名:"<<given_name1<<endl<<"民族:"<<CMother ::nation<<endl<<"年龄:20"<<endl;
}
调试出错:
c:\documents and settings\aa\桌面\vc\任子健第三次作业\3 66\3 66main.cpp(5) : error C2597: illegal reference to data member 'CFather::family_name' in a static member function
c:\documents and settings\aa\桌面\vc\任子健第三次作业\3 66\3 66main.cpp(5) : error C2065: 'given_name1' : undeclared identifier
执行 cl.exe 时出错.
大家帮忙看看是什么原因造成的,怎么改?谢谢!!!
[ 本帖最后由 yydjtcy 于 2009-10-20 21:07 编辑 ]