枚举类型怎么用的啊?
#include<iostream>
using namespace std;
class Person{
public:
char *name;
enum sex{Male,Female};
sex sex1;
double id;
void toString()
{
cout<<"name:"<<*name<<endl;
cout<<"sex1:"<<sex1<<endl;
cout<<"id:"<<id<<endl;
}
};
class Student: public Person
{
private:
double no,score;
public:
void toString()
{
cout<<"name:"<<*name<<endl;
cout<<"sex1:"<<sex1<<endl;
cout<<"id:"<<id<<endl;
cout<<"no:"<<no<<endl;
cout<<"score:"<<score<<endl;
}
};
class Teacher: public Person
{
private:
enum postion{Prof,AssociateProf,AssistProf};
postion postion1;
public:
void toString()
{
cout<<"name:"<<*name<<endl;
cout<<"sex1:"<<sex1<<endl;
cout<<"id:"<<id<<endl;
cout<<"postion:"<<postion1<<endl;
}
};
int main()
{
Person person("li",Male,520320);
person.toString();
Student student("wang",Female,520321,19,89);
student.toString();
Teacher teacher("wu",Male,520250,Prof);
teacher.toString();
system("pause");
return 0;
}
编译时 总是报错 C:\Users\Administrator\Desktop\作业2.cpp In function `int main()':
50 C:\Users\Administrator\Desktop\作业2.cpp `Male' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
52 C:\Users\Administrator\Desktop\作业2.cpp `Female' undeclared (first use this function)
54 C:\Users\Administrator\Desktop\作业2.cpp `Prof' undeclared (first use this function)
我想请教一下枚举类型是怎么用的啊, 可以给个经典例子么 谢谢!