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.
documentation for std::stack
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With