【问题标题】:C++ STL::map containing STL::deque (cannot convert from 'void' to class*)包含 STL::deque 的 C++ STL::map(不能从 'void' 转换为 class*)
【发布时间】:2021-06-22 18:10:48
【问题描述】:

尝试将双端队列中的元素分配给用户定义的类时出现以下错误。

    map<unsigned int, std::deque<Order*>>::iterator itBuyPrices =buyPrices.begin();
    Order *buyOrder;
    buyOrder = itBuyPrices->second.pop_back();

赋值行(第 3 行)出现错误: 错误 C2440 '=':无法从 'void' 转换为 'Order *'

【问题讨论】:

  • 查看pop_back 返回的内容。这会让你大吃一惊。
  • 解决方法是从第三行代码中删除pop_ 字符,然后您将留下back()
  • 谢谢你(问这个我觉得很傻)

标签: c++ dictionary stl deque


【解决方案1】:

deque::pop_back() 返回void,即什么都没有。您需要先使用deque::back() 访问队列中的最后一项,然后再调用pop_back() 将其删除,例如:

map<unsigned int, std::deque<Order*>>::iterator itBuyPrices = buyPrices.begin();
Order *buyOrder = itBuyPrices->second.back();
itBuyPrices->second.pop_back();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-12
    • 1970-01-01
    • 2011-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多