Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conversion from ‘void’ to non-scalar type ‘std::pair<std::basic_string<char, std::char_traits<char>

Tags:

c++

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?

like image 241
Deekor Avatar asked Apr 23 '13 03:04

Deekor


1 Answers

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

like image 196
Captain Obvlious Avatar answered Sep 21 '22 00:09

Captain Obvlious