c++ - 说它不能用作常数
问题描述
视觉工作室 2019
const int inputs = 1, layers = 2, layerN = 3, output = 1;
const int how = inputs * layerN + pow(layerN,layers) + output * layerN;
float w[how];
它说它w[how]
必须是“const”表达式(但是是??)
我无法运行此错误的程序。
帮助。
解决方案
how
不是常量表达式。它的值在编译时不为编译器所知,它是在运行时动态计算的,因为函数调用pow()
. 因此,它不能用于声明固定长度的数组。您将不得不使用new[]
orstd::vector
代替:
float *w = new float[how];
...
delete[] w;
#include <vector>
std::vector<float> w(how);
推荐阅读
- javascript - 尝试使用 Node.Js 和 Mongoose 将 API 数据发送到 MongoDB
- python - Lepton PureThermal 在 Python3 OpenCV 中不起作用
- recursion - 为什么这个递归 Pascal 过程没有陷入无限循环?
- java - 将状态传递给每个行为是否使其成为“上帝对象”
- .net - 如何在不更新文件上传字段的情况下更新实体
- sql - 将一个表定义为高于另一个表的优先级,然后根据表优先级选择属性
- snakemake - 我可以为snakemake 定义一个默认配置文件吗?
- r - Tidymodels - 在 XGBoost 分类模型中使用 PCA 输出
- node.js - 通过对象相等测试查找 Mongo 文档
- terraform - Terraform:错误:提供程序配置不存在