我有sdl2文档中的以下代码:
//Color declartions for later
Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
代码块告诉我条件为真,但是在编译时,告诉我rmask没有命名类型。该错误从else语句的第一行开始标记。首先,如何避免这种情况?其次,我是否甚至需要if语句?
完整的错误日志为:
||=== Build: Debug in hayfysh (compiler: GNU GCC Compiler) ===|
/home/andrew/hayfysh/main.cpp|57|error: ‘rmask’ does not name a type|
/home/andrew/hayfysh/main.cpp|58|error: ‘gmask’ does not name a type|
/home/andrew/hayfysh/main.cpp|59|error: ‘bmask’ does not name a type|
/home/andrew/hayfysh/main.cpp|60|error: ‘amask’ does not name a type|
/home/andrew/hayfysh/main.cpp||In function ‘int newWindow(int, int, bool, const char*)’:|
/home/andrew/hayfysh/main.cpp|90|error: cannot convert ‘const char*’ to ‘FILE* {aka _IO_FILE*}’ for argument ‘1’ to ‘int fprintf(FILE*, const char*, ...)’|
||=== Build failed: 5 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
通过将fprintf更改为printf已经解决了第五个错误
最佳答案
假设此代码恰好是问题发生的地方(即,它不是从函数的中间提取的),那么问题是在全局范围内不允许使用赋值语句。更改它以初始化变量(应将其标记为const吗?):
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
Uint32 rmask = 0xff000000;
Uint32 gmask = 0x00ff0000;
Uint32 bmask = 0x0000ff00;
Uint32 amask = 0x000000ff;
#else
Uint32 rmask = 0x000000ff;
Uint32 gmask = 0x0000ff00;
Uint32 bmask = 0x00ff0000;
Uint32 amask = 0xff000000;
#endif
关于c++ - C++ Rmask没有命名类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34372692/