Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在C++;哎呀_C++_Visual Studio_Oop_Enums - Fatal编程技术网

C++ 在C++;哎呀

C++ 在C++;哎呀,c++,visual-studio,oop,enums,C++,Visual Studio,Oop,Enums,在我的计算机科学课上,我的头文件中有一个枚举值,我在get和set函数方面遇到了问题。我对C++很陌生。这是我的头文件的一部分: enum class SchoolType { Elementary = 1, Secondary = 2 }; class School : public Institution { public: // There are a couple more values here SchoolType GetSchoo

在我的计算机科学课上,我的头文件中有一个枚举值,我在get和set函数方面遇到了问题。我对C++很陌生。这是我的头文件的一部分:

enum class SchoolType {
    Elementary = 1,
    Secondary = 2
};

class School : public Institution
{
    public:
        // There are a couple more values here

    SchoolType GetSchoolType();
    void SetSchoolType(SchoolType typeSchool);
};
这是我的.cpp文件的一部分:

SchoolType GetTypeSchool()
{
    return this->_typeSchool;
}
void SetTypeSchool(SchoolType typeSchool)
{

}

但是“this”带来了一个错误,并表示“this”只能在非静态成员函数中使用。我怎样才能使该函数工作?我的计算机老师告诉我,这就是我应该如何编写get函数的方法,但我仍然不明白,标题中是否有错误?

对于.cpp文件,您应该:

SchoolType School::GetSchoolType() {
    return this->_typeSchool;
}
void School::SetSchoolType(SchoolType typeSchool) {
    // Insert code here...
}
<>基本上,在C++中,当定义成员函数时,需要指定函数是什么(在这种情况下是“代码>学校< /代码>”的一个类,或者编译器不把它看作是任何类的一部分。您还需要保持方法名称的一致性(
GetSchoolType
vs
GetTypeSchool