c++ - 创建数组时出错:表达式必须具有常量值
问题描述
我正在研究使用 Hu Moment 提取功能识别手势的代码,从这里输入链接描述,但我在声明数组时遇到问题
int matchTheState(vector<Point> present_hand_state, vector<vector<Point > > MyContours)
{
double array[MyContours.size()];
而 的内容vector<vector<point>> MyContours
是用作比较值的图像声明。
错误说:
expression must have constant value (cannot call non-constecxpr function...)
function call must have a constant value in a constant expression
解决方案
在 C++ 中,数组边界必须是编译时常量。MyContours.size()
不是编译时间常数。只需使用向量即可。
vector<double> array(MyContours.size());
推荐阅读
- grails - 如何在 Grails4 / GORM7 中使用空间类型?
- javascript - 如何使用 Express 服务于 Webpack 编译的前端?
- html - 将子 div 扩展到表 div 父级的高度
- angular - 数据保存在本地存储但刷新时不显示
- ibm-mq - JMS 连接数让我在 Netstat/MQ 资源管理器中感到困惑
- javascript - 访问对象数组中对象的ID,ReactJS
- c# - 如何从 C# 程序获取 WSL2 IP 地址?
- java - Scanner.findAll() 和 Matcher.results() 对于相同的输入文本和模式的工作方式不同
- reactjs - 如何在 recharts 中使用 .map 函数创建双轴 LineChart
- azure-devops - 如何使我的 Powershell 市场任务可以访问 Secret 变量(在 Azure 发布管道中定义)?