如何解决“与参数不兼容的类型参数”错误?

时间:2019-07-16 16:47:55

标签: c++ class enums

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);
}

错误状态:“度”类型的参数与“度”类型的参数不兼容。我以为学位是一个枚举,网络也是一个枚举。

1 个答案:

答案 0 :(得分:0)

正如评论中的其他人所提到的,您实际上在这里寻找的是degree::NETWORKING。原因是您打算使用NETWORKING' is part of the enum, and not in the global space. Thus, you need to specify which网络`。