头文件中的枚举
我在名为“sm.h”的头文件中声明了枚举,
enum GameStates
{
STATE_NULL = 0,
STATE_INTRO,
STATE_TITLE,
STATE_MAIN,
STATE_EXIT
};
它所做的只是列出可能的游戏状态,
但是在“base.cpp”中的以下行中:
stateID = STATE_INTRO;
编译器表示“STATE_INTRO 未在此范围内声明”。我不知道我做错了什么。我知道我已经包含了正确的头文件,我可以从 .cpp 文件中转到它的减速。那么为什么我会收到此错误。
stateID = STATE_INTRO;
用于:
bool baseFunctions::load_rc()
{
stateID = STATE_INTRO;
currentState = new Intro();
return true;
}
在头文件中定义类函数。
不存在全局冲突,因为它是整个程序中唯一的枚举
I have enum declared in a header file called "sm.h"
enum GameStates
{
STATE_NULL = 0,
STATE_INTRO,
STATE_TITLE,
STATE_MAIN,
STATE_EXIT
};
All it does is list the possible game states
However in the following line in "base.cpp":
stateID = STATE_INTRO;
The compiler says "STATE_INTRO was not declared in this scope". I have no idea what I am doing wrong. I know that I have included the header file right and I can go to its deceleration from the .cpp file. So why am I getting this error.
stateID = STATE_INTRO;
Is used in:
bool baseFunctions::load_rc()
{
stateID = STATE_INTRO;
currentState = new Intro();
return true;
}
which defines a class function in a header file.
There are no global conflicts because it is the only enum in the whole program
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最有可能的是您没有在 base.cpp 中包含“sm.h”
Most likely is that you aren't including "sm.h" in base.cpp
从您的文件链接中,
sm.h
和base.h
中都有以下内容将
sm.h
中的内容更改为其他内容就像,我希望你会没事的。
事实上,
base.cpp
加载base.h
,然后当它到达sm.h
时,#ifndef 为 false,因此它排除了sm.h
中的所有内容。From your link to your files, you have the following in both
sm.h
andbase.h
Change the one in
sm.h
to something likeand I expect you'll be fine.
As it is,
base.cpp
loadsbase.h
, then when it gets tosm.h
the #ifndef is false, so it excludes everything insm.h
.