来自当地大学夜校的C#背景,我开始用C++开始了.习惯了语法很痛苦.在编码技术方面,我还是非常环保.
从我的WinMain函数,我希望能够访问一个使用我在另一个类中声明的枚举的变量.
(inside core.h)
class Core
{
public:
enum GAME_MODE
{
INIT,
MENUS,
GAMEPLAY
};
GAME_MODE gameMode;
Core();
~Core();
...OtherFunctions();
};
(inside main.cpp)
Core core;
int WINAPI WinMain(...)
{
... startup code here...
core.gameMode = Core.GAME_MODE.INIT;
...etc...
}
Run Code Online (Sandbox Code Playgroud)
基本上我想将gameMode设置Init为我的WinMain函数中的枚举值或类似值.我也希望能够从其他领域阅读它.
我收到了错误......
expected primary-expression before '.' token
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用core.gameMode = Core::GAME_MODE.INIT;,那么我会得到同样的错误.
我并不喜欢最佳实践,因为我只是试图获得在文件之间传递C++变量的基本理解.一旦我习惯了语法的灵活性,我将确保变量受到保护并且稍后整齐地隐藏起来.
如果我没记错的话,C#允许我使用其他课程的Enums,我所要做的就是这样Core.ENUMNAME.ENUMVALUE.
我希望我想要做的是明确的:\我不知道很多正确的术语是什么.
所以这是我的问题:
struct A
{
enum A_enum
{
E0,
E1,
E2
};
};
struct B
{
typedef A::A_enum B_enum;
bool test(B_enum val)
{
return (val == E1); // error: "E1" undeclared identifier
}
};
Run Code Online (Sandbox Code Playgroud)
我特意不想说A::E1.如果我尝试,B_enum::E1我会收到一个非标准的警告.有没有办法做这样的事情?