【发布时间】:2020-03-05 11:56:07
【问题描述】:
我将一个三维数组声明为类成员,使用静态 const 类成员作为前两个边界:
class A
{
static const uint8_t screenWidth = 256;
static const uint8_t screenHeight = 240;
uint8_t buffer[screenHeight][screenWidth ][3];
}
在 Visual Studio 2019 中,我收到以下(奇怪的?)错误:
Error (active) E0098 an array may not have elements of this type
如果我使用“枚举破解”来声明类本地编译时整数常量,它可以工作:
class A
{
enum { SH = 240, SW = 256};
uint8_t buffer[SH][SW][3];
}
前一个示例不应该是符合 C++11 的代码吗? (我猜是 Visual Studio 2019 编译器)。
【问题讨论】:
-
@stark
const和constexpr在这种情况下具有相同的效果。整数类型有特殊的规则。
标签: c++ arrays initialization constants