【发布时间】:2020-07-06 07:31:02
【问题描述】:
我正在尝试计算条目的平均值,但由于某种原因,我遇到了意外错误:
error: no match for ‘operator+’ (operand types are ‘double’ and ‘const OrderBookEntry’)
__init = __init + *__first;"
~~~~~~~^~~~~~~~~~
我是 C++ 新手,曾尝试解决此问题一段时间,但没有任何效果。
int MerkelBot::predictMarketPrice()
{
int prediction = 0;
for (std::string const& p : orderBook.getKnownProducts())
{
std::cout << "Product: " << p << std::endl;
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookType::ask,
p, currentTime);
double sum = accumulate(entries.cbegin(), entries.cend(), 0.0);
prediction = sum / entries.size();
std::cout << "Price Prediction is: " << prediction << std::endl;
}
}
【问题讨论】:
-
如何“添加”两个
OrderBookEntry对象?也许您应该使用std::accumulate的重载,在其中提供执行“添加”的谓词?
标签: c++ operator-overloading accumulate