I have a stack of pairs in a 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. You need to call top()
in order to retrieve the element before you pop it off the stack.
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.
Your pop()
function of the stack returns void
. you have type mismatch.
You should call undoStack.top()
instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.