简体   繁体   English

C++ STL::map 包含 Z2523E0C272CB676C4F59F978289966

[英]C++ STL::map containing STL::deque (cannot convert from 'void' to class*)

I get the following error when trying to assign a element from a deque to a user defined class.尝试将双端队列中的元素分配给用户定义的 class 时出现以下错误。

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

ERROR at the assignment line (3rd line): Error C2440 '=': cannot convert from 'void' to 'Order *'赋值行(第 3 行)错误:错误 C2440 '=':无法从 'void' 转换为 'Order *'

deque::pop_back() returns void , ie nothing. deque::pop_back()返回void ,即什么都没有。 You need to use deque::back() to access the last item in the queue before then calling pop_back() to remove it, eg:您需要先使用deque::back()访问队列中的最后一项,然后再调用pop_back()将其删除,例如:

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM