C++中boost多数组的维数

7hiiyaii  于 2024-01-09  发布在  其他
关注(0)|答案(1)|浏览(269)

当我运行下面的警告标志时,我得到一个类型转换警告。

  1. #include <boost/multi_array.hpp>
  2. void function (boost::multi_array<unsigned char, 2> matrix) {
  3. int nrows = matrix.shape()[0];
  4. int ncols = matrix.shape()[1];
  5. }

字符串
这是否意味着我隐式地将'long unsigned int'转换为常规'int'?
如果是这样,我想这就是我想要的(之后需要使用nrows和ncrow执行计算),那么我如何使转换显式化?

  1. image.cpp:93:32: warning: conversion to int from boost::const_multi_array_ref<float, 2ul, float*>::size_type {aka long unsigned int}’ may alter its value [-Wconversion]
  2. int nrows = matrix.shape()[0];

dfuffjeb

dfuffjeb1#

  • 这是否意味着我隐式地将'long unsigned int'转换为常规'int'?*

是的,就是这个意思。
如果你不想要警告,那么就不要让nrowsncols的类型为int。最简单的方法是让编译器推导出类型,即。

  1. auto nrows = matrix.shape()[0];
  2. auto ncols = matrix.shape()[1];

字符串
或者你可以把它们设置为size_t类型,这是标准库用来表示容器大小的类型,不会发出警告。

相关问题