栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c++(6):error: incompatible types in assignment of ‘int*’ to ‘int [2]’

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c++(6):error: incompatible types in assignment of ‘int*’ to ‘int [2]’

报错、原因、解决办法:
error: incompatible types in assignment of ‘int*’ to ‘int [2]’

原因:

        将函数返回值的类型“int*”强制转化为“int[2]”类型失败

解决办法:

        用一个“int*”的中间变量接收函数返回值,再转化为“int[2]”类型

修改前c++代码:

参数声明部分:

//参数声明
double point_start[3]={0.0,0.0,0.0};//起点位姿
double map_origin[2]={0.0,0.0};//地图原点
float resolution;//地图分辨率
int point_start_index[2]={0,0};//起点在地图中的坐标索引  

计算坐标索引的函数(返回值为int *类型)

int * compute_point_index(double point[]){
  int point_index[2];
  point_index[0]=(point[0]-map_origin[0])/resolution;
  point_index[1]=(point[1]-map_origin[1])/resolution;
  return point_index;
}

主程序:

//主程序
point_start_index=compute_point_index(point_start);
修改后c++代码:

函数部分:修改第二行数组类型,保证在跳出函数时数组没有被销毁:

int * compute_point_index(double point[]){
  static int point_index[2];
  point_index[0]=(point[0]-map_origin[0])/resolution;
  point_index[1]=(point[1]-map_origin[1])/resolution;
  return point_index;
}

主程序部分:

  int * point_index;
  point_index=compute_point_index(point_start);
  point_start_index[0]=*point_index;point_start_index[1]=*(point_index+1);

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/998091.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号