小编Rix*_*ugh的帖子

如何使涉及浮点函数的表达式成为编译时常量?

我有一个常量整数,steps,它是使用其他两个常量变量的商的下限函数计算的。但是,当我尝试使用它作为数组的长度时,Visual Studio 告诉我它必须是一个常量值,并且当前值不能用作常量。如何使其成为可用作数组长度的“真实”常量?楼层功能是否有问题?我可以使用其他替代方案吗?

const int simlength = 3.154*pow(10,7);
const float timestep = 100;
const int steps = floor(simlength / timestep);

struct body bodies[bcount];

struct body {
    string name;
    double mass;
    double position[2];
    double velocity[2];
    double radius;
    double trace[2][steps];
};
Run Code Online (Sandbox Code Playgroud)

c++ arrays variables

4
推荐指数
1
解决办法
320
查看次数

标签 统计

arrays ×1

c++ ×1

variables ×1