#include <iostream.h>
#include <string.h>
class teacher
{
char name[5];
int age;
char sex;
char address[20];
int number;
char title[10];
public:
void set(char *,int,char,char*,int,char*);
virtual void display()
{
cout<<"姓名"<<name<<" 年龄"<<age<<" 性别"<<sex<<" 地址"<<address<<" 电话"<<number<<" 职称"<<title<<endl;
}
};
void teacher::set(char *a,int b,char c,char *d,int n,char *t)
{
strcpy(name,a);
age=b;
sex=c;
strcpy(address,d);
number=n;
strcpy(title,t);
}
class cadre
{
char name[5];
int age;
char sex;
char address[20];
int number;
char post[10];
public:
void set(char*,int,char,char*,int,char*);
char *get()
{
return post;
}
};
void cadre::set(char *a,int b,char c,char *d,int n,char *t)
{
strcpy(name,a);
age=b;
sex=c;
strcpy(address,d);
number=n;
strcpy(post,t);
}
class teacher_cadre:public teacher,public cadre
{
int wage;
public:
void set(int );
void show();
};
void teacher_cadre::set(int b)
{
wage=b;
}
void teacher_cadre::show()
{
teacher::display();
cout<<"工资"<<wage<<"职务"<<cadre::get()<<endl;
}
void main()
{
teacher::set("Job",20,'M',"Beijing",502520,"jiaoshou");
cadre::set("Job",20,'M',"Beijing",502520,"kezhang");
teacher_cadre C;
C.set(2500);
C.show();
}
提示错误:
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
I:\1\1.cpp(73) : error C2352: 'teacher::set' : illegal call of non-static member function
I:\1\1.cpp(12) : see declaration of 'set'
I:\1\1.cpp(74) : error C2352: 'cadre::set' : illegal call of non-static member function
I:\1\1.cpp(36) : see declaration of 'set'
Error executing cl.exe.