C++的新手,我为"学位"创建了一个枚举,其中包含 3 种类型"安全、网络、软件",当子类尝试使用枚举时会返回类型错误。它专门寻找什么类型?
//Network Student Subclass
#include <string>
#include "degree.h"
#include "student.h"
class NetworkStudent : public Student //This class derives from Student
{
public:
NetworkStudent();
NetworkStudent(
string student_id,
string first_name,
string last_name,
string email,
double age,
double* days,
degree type
);
degree getdegree();
void setdegree(degree d);
void print();
~NetworkStudent();
};
//Enum with 3 Types
#include <string>
//The three types of degrees available
enum degree {SECURITY,NETWORKING,SOFTWARE};
static const std::string degreeTypeStrings[] = { "SECURITY","NETWORKING", "SOFTWARE" };
//Network Student definition with invalid type error for NETWORKING
#include "student.h"
#include "networkStudent.h"
using std::cout;
NetworkStudent::NetworkStudent()
{
//Right here is where I get the error on NETWORKING
setdegree(NETWORKING);
}
错误状态:"度"类型的参数与"度"类型的参数不兼容。我认为学位是一个枚举,网络也是一个枚举。
正如评论中的其他人所提到的,您在这里寻找的内容实际上是degree::NETWORKING
.原因是NETWORKING
是枚举degree
的一部分,而不是在全局空间中。因此,您需要指定要使用的NETWORKING
。