gpt4 book ai didi

c++ - 不能出现在常量表达式中

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:32:05 24 4
gpt4 key购买 nike

在下面的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)' cannot appear in a constant-expression。为什么我会遇到这个问题,因为我在前面放了一个整数?我应该如何解决这个问题?

最佳答案

编译器引用的常量表达式实际上是数组tab 的边界。静态分配数组的维度必须在编译时已知,但 row 的值直到运行时才能确定,因为它是使用函数求值的。

关于c++ - 不能出现在常量表达式中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5929766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com