[英]conversion from ‘void’ to non-scalar type ‘std::pair<std::basic_string<char, std::char_traits<char>
I have a stack of pairs in a spreadsheet
obj: 我在spreadsheet
obj中有一堆对:
std::stack< std::pair<std::string, std::string> > undoStack;
And I am trying to pop the stack and assign it to another pair: 我试图弹出堆栈并将其分配给另一对:
std::pair<std::string, std::string> change = spreadsheets.at(i).undoStack.pop();
And I am getting this error: 我收到这个错误:
error: conversion from ‘void’ to non-scalar type ‘std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’ requested
Whats going wrong here? 这里出了什么问题?
stack::pop()
returns void but you are attempting to assign it to a variable. stack::pop()
返回void但您正在尝试将其分配给变量。 You need to call top()
in order to retrieve the element before you pop it off the stack. 您需要调用top()
以便在将其从堆栈中弹出之前检索该元素。
std::pair<std::string, std::string> change = spreadsheets.at(i).undoStack.top();
spreadsheets.at(i).undoStack.pop();
You should look at the documentation for std::stack
to get familiar with it's member functions and use. 您应该查看std::stack
的文档以熟悉它的成员函数和使用。
Your pop()
function of the stack returns void
. 堆栈的pop()
函数返回void
。 you have type mismatch. 你有类型不匹配。
You should call undoStack.top()
instead. 你应该调用undoStack.top()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.