不能出现在常量表达式中
在下面的 C++ 程序中:
static const int row = (dynamic_cast<int>(log(BHR_LEN*G_PHT_COUNT)/log(2)));
static const int pht_bits = ((32*1024)/(G_PHT_COUNT * G_PHT_COUNT * BHR_LEN));
unsigned char tab[pht_bits][1<<row];
我收到错误消息 double log(double)' can not出现在常量表达式中。 既然我在前面放置了整数转换,为什么我会遇到这个问题?我应该如何解决这个问题?
In the following c++ program:
static const int row = (dynamic_cast<int>(log(BHR_LEN*G_PHT_COUNT)/log(2)));
static const int pht_bits = ((32*1024)/(G_PHT_COUNT * G_PHT_COUNT * BHR_LEN));
unsigned char tab[pht_bits][1<<row];
I get the error message double log(double)’ cannot appear in a constant-expression.
why am I getting this problem since i have put an integer cast in front? How should i fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编译器引用的常量表达式实际上是数组
tab
的边界。静态分配数组的维度必须在编译时已知,但 row 的值要到运行时才能确定,因为它是使用函数求值的。The constant-expression that the compiler is referring to is actually the bounds of the array
tab
. The dimensions of statically allocated arrays have to be known at compile-time, but the value ofrow
can't be determined until runtime, because it is evaluated using a function.对于那些对我的回答投反对票的人。告诉我这段代码不起作用:
原始(从 (int) 更改为 static_cast,这并不重要)
To you that are downvoting my answer. Tell me that this code does not work:
Original (changed from (int) to static_cast, not that it matters)