Vaios Argiropoulos
Vaios Argiropoulos

Reputation: 387

error: Invalid use of void expression , in a class method declaration

Here's the deal. I am trying to build an EditorBuffer class (for text editing of a single line).

The class consists of two stacks of characters (stack<char> before , stack<char> after) where the before stack represents all the characters which are situated before the "cursor" while the after stack represents all the characters after the "cursor". In the declaration shown below i got the error error: Invalid use of void expression which is totally alien to me.

Here is the method declaration:

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

}

Upvotes: 2

Views: 1674

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272657

std::stack::pop() doesn't return anything (its return type is void). You probably want to do:

before.push(after.top());
after.pop();

Upvotes: 6

Related Questions