这是一个说明我的问题的简化示例。以下是我的:error C2065: 'State' : undeclared identifier
我的类.h
class MyClass
{
enum class State { IDLE, WALK_RIGHT, WALK_LEFT };
void SetState(State);
}
我的类.cpp
#include "myclass.h"
void SetState(State state)
{
//...
}
知道这里出了什么问题吗?提前致谢!
最佳答案
这不是您在类定义之外定义成员函数的方式。你需要
void MyClass::SetState(State state){
// ^^^^^^^^^
}
编译器在看到 MyClass::SetState
并意识到这是一个成员函数定义后,就会知道在 MyClass
中寻找 State
,因此您不必在此处编写 MyClass::State
。
关于c++ - 将枚举作为函数参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28652901/