简体   繁体   English

int32_t 和 int64_t 转换问题

[英]int32_t and int64_t Conversion Issues

In the following line of code, positive is a vector of int32_t elements.在下面的代码行中, positive是一个包含int32_t元素的向量。

int32_t pos_accum = accumulate(positive.begin(), positive.end(), std::multiplies<int32_t>());

The compiler generates the following error that seems to make no sense:编译器生成以下似乎没有意义的错误:

No suitable conversion function from "std::multiplies<int32_t>" to "int32_t" exists

as well as

'initializing': cannot convert from '_Ty' to 'int32_t'

The ultimate goal is to store the answer in an int64_t , but attempts to static_cast<int64_t> the result ends up in similar errors.最终目标是将答案存储在int64_t中,但尝试static_cast<int64_t>结果以类似错误告终。

Any idea what the problem is here?知道这里的问题是什么吗?

The signature of std::accumulate that accepts a binary operator is接受二元运算符的std::accumulate的签名是

template< class InputIt, class T, class BinaryOperation >
constexpr T accumulate( InputIt first, InputIt last, T init, BinaryOperation op );

You're missing the init argument, which represents the initial value of the accumulation.您缺少init参数,它表示累加的初始值。 Try尝试

accumulate(positive.begin(), positive.end(), 1, std::multiplies<int32_t>());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 动态整数大小:int64_t,int32_t,uint32_t等 - Dynamic Integer Size: int64_t, int32_t, uint32_t, etc 将int64_t或int32_t分配给ptrdiff_t是否正确? - Is it correct to assign int64_t or int32_t to ptrdiff_t? 当int64_t更改为int32_t时,为什么类大小会增加 - Why class size increases when int64_t changes to int32_t 从char数组获取int32_t或int64_t值 - Getting a int32_t or a int64_t value from a char array stdint 类型与原生类型:long 与 int64_t、int32_t - stdint types vs native types: long vs int64_t, int32_t int32_t的延迟是否低于int8_t,int16_t和int64_t? - Does int32_t have lower latency than int8_t, int16_t and int64_t? 在32位系统上使用int64_t而不是int32_t会对性能产生什么影响? - what is the performance impact of using int64_t instead of int32_t on 32-bit systems? 使用和何时使用 int16_t、int32_t、int64_t 和分别为 short int、int、long int、long - Uses and when to use int16_t,int32_t,int64_t and respectively short int,int,long int,long 函数msg(long)的候选函数msg(int32_t)和msg(int64_t)的模棱两可的重载 - Ambiguous overload of functions like `msg(long)` with candidates `msg(int32_t)` and `msg(int64_t)` C或C ++中的标准宏是否代表int32_t,int64_t的最大值和最小值? - Is there a standard macro in C or C++ represent the max and min value of int32_t, int64_t?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM