如何做size_t乘法
how to do size_t multiplication
size_t size, reshape_size;
size = somemethod()
for (size_t index = 0; index < *dim; ++index)
reshape_size = reshape_size*shape[index];
if (reshape_size == size){
...
我收到错误
error: invalid type argument of unary ‘*’ (have ‘size_t {aka long unsigned int}’)
那么我该如何进行乘法呢?我必须比较两个size_t,如前所见。
问题不在于乘法,而在于取消引用dim
。dim
是指针吗?没有。index < *dim
应该是什么意思?
另外,我认为您(错误地)假设size_t size, reshape_size;
将被初始化为某些东西。因为reshape_size = reshape_size*shape[index];
是未定义的,因为reshape_size
没有初始化。
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 使用std::vector的OpenCL矩阵乘法
- 大于65535的C++数组[size]引发不一致的溢出
- 矩阵向量乘法(cublasDgemv)返回零
- 为什么(-1)%vector::size()总是返回0
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 循环中的条件:为什么每次都调用strlen(),而vector.size()只调用一次
- 组装指令中乘法的下部和上部是什么
- 在 C++ 中使用 SIMD 向量的矩阵乘法
- 为什么这个 std::queue/指向结构的指针列表直到 List.Size() == 0 才释放内存?
- 在函数中使用 const int size 参数创建数组会在 Visual Studio 中抛出错误 C++:表达式的计
- 如何知道n!是否可以表示为三个连续数字的乘法?
- vector.size() 在比较中意外工作
- vector.back() 和 vector[vector.size() - 1] 之间的区别?
- 使用运算符*重载包装矩阵乘法
- 返回 str vs. str.substr(0,str.size()) 在 leetcode 中给了我不同的输出
- 在实践中,在运行时为零的乘法中是否有任何"lazy"评估
- 更改一个指针后更改乘法对象
- 为什么 GCC 不能假设 std::vector::size 在这个循环中不会改变?
- 为什么"(!v.empty())"比"(v.size() >0)"好?