错误:在类方法声明中无效使用void表达式

Vai*_*los 2 c++

这是交易.我正在尝试构建一个EditorBuffer类(用于单行的文本编辑).

该类由两个字符堆组成,(stack<char> before , stack<char> after)其中前堆栈表示位于"游标"之前的所有字符,而后堆栈表示"游标"之后的所有字符.在下面显示的声明中,我得到的错误error: Invalid use of void expression对我来说完全不同.

这是方法声明:

void EditorBuffer::moveCursorToEnd()
{
    while (!after.empty())
    {
        before.push(after.pop());
    }

}
Run Code Online (Sandbox Code Playgroud)

Oli*_*rth 6

std::stack::pop()不返回任何东西(它的返回类型是void).你可能想做:

before.push(after.top());
after.pop();
Run Code Online (Sandbox Code Playgroud)