error C2065: ✀level✀ : undeclared identifier怎么解决

2024-12-16 05:42:54
推荐回答(1个)
回答1:

#include
#include
using namespace std;
class University
{
public:
University(string name1,int age1)
{name=name1;
age = age1;
}
void print()
{cout<<"姓名:"< cout<<"年龄:"< }
protected:
string name;
int age;
};
class Student:virtual public University
{
public:
int level;//第一该字段
Student(string name1,int age1,long int stu_no1,string major1,int level1):University(name1,age1)
{stu_no=stu_no1;
major=major1;
level=level1;
}
void print()
{University::print();
cout<<"学号:"< cout<<"专业:"< cout<<"年级:"< }
protected:
long int stu_no;
string major;
};
class Teacher:virtual public University
{
protected:
string dept;
string title;
double salary;
public:
Teacher(string name1,int age1,string dept1,string title1,double salary1):University(name1,age1)
{dept=dept1;
title=title1;
salary=salary1;
}
void print()
{University::print();
cout<<"系别:"< cout<<"职称:"< cout<<"工资:"< }
};

class T_student:public Teacher,public Student
{
public:
T_student(string name1,int age1,long int stu_no1,string major1,int level1,string dept1,string title1,double salary):
University(name1,age1),Teacher(name1,age1,dept1,title1,salary),Student(name1,age1,stu_no1,major1,level1)
{}
void print()
{
Student::print();
cout<<"系别:"< cout<<"职称:"< cout<<"工资:"< };
};

void main()
{
Student my_Student("张三",20,0001,"软件设计",1);
cout<<"普通大学生:"< my_Student.print();

Teacher my_Teacher("李四",30,"计科系","教授",5000);
cout<<"教师:"< my_Teacher.print();

//T_student(string name1,int age1,long int stu_no1,string major1,int level1,string dept1,string title1,double salary):
T_student my_T_student("王五",21,0003,"日语",2,"无赖系","糊涂官",-1000);
cout<<"兼职学生:"< my_T_student.print();
}
///记得给分哦