如何做size_t乘法

how to do size_t multiplication

本文关键字:乘法 size 何做      更新时间:2023-10-16
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,如前所见。

问题不在于乘法,而在于取消引用dimdim是指针吗?没有index < *dim应该是什么意思?

另外,我认为您(错误地)假设size_t size, reshape_size;将被初始化为某些东西。因为reshape_size = reshape_size*shape[index];是未定义的,因为reshape_size没有初始化。