Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6173691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:37:13+00:00 2026-05-23T23:37:13+00:00

Edit: Added token struct/enum to code block I’m new to c++, so forgive me

  • 0

Edit: Added token struct/enum to code block

I’m new to c++, so forgive me if I missed something obvious. I’m trying to write a c++ version of the Shunting Yard Algorithm, but it won’t compile because it gives me the error: “cannot convert from ‘void’ to ‘Token’ (on the line I marked).” Can anyone tell me why it gives this error?

typedef enum TokenType { None, Number, Operator, LeftParens, RightParens };

struct Token
{
    enum TokenType type;
    union
    {
        int num;
        char op;
    };
};

list<Token> DoShuntingYard(list<Token> tokenList)
{
    stack<Token> opStack;
    list<Token> output;
    while (!tokenList.empty())
    {
        ****(This Line) Token t = tokenList.pop_front();
        switch (t.type)
        {
        case Number:
            output.push_back(t);
            break;
        case Operator:
            if (!opStack.empty())
            {
                Token op2 = opStack.top();
                if ((IsLeftAssoc(t) && GetOpPrecedence(t) <= GetOpPrecedence(op2)) || (!IsLeftAssoc(t) && GetOpPrecedence(t) < GetOpPrecedence(op2)))
                {
                    output.push_back(opStack.pop());
                }
            }
            break;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:37:15+00:00Added an answer on May 23, 2026 at 11:37 pm

    The problem is that pop_front does not return a value. If you want to remove the first element and read its value, you can do so in two steps:

    Token t = tokenList.front();
    tokenList.pop_front();
    

    This convention is employed throughout the STL, mostly for efficiency reasons. By having front return the value and pop_front return nothing, you can capture the value if you want, but if you just want to remove the value you can do so without making an unnecessary copy of the removed object by just calling pop_front.

    You will run into a similar error later on with this code:

    output.push_back(opStack.pop());
    

    To fix this, split this into two lines:

    output.push_back(opStack.top());
    opStack.pop();
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code: EDIT: The _penParams are initialized as the added
In the following code why does mockTest.ToString() return Null? EDIT: Added comment into example
EDIT - added .h file I'm having difficulty trying to find the cause of
EDIT: I have added Slug column to address performance issues on specific record selection.
Edit: You can get the full source here: http://pastebin.com/m26693 Edit again: I added some
EDIT: Modified title and added update. UPDATE : We no longer believe this is
EDIT : Accepted answer points out what my issue was. I added another answer
in C# I'd like to invoke the label edit of a newly added item
My company is fairly new to unit testing our code. I've been reading about
Is it possible to add/create new history token from every class? I have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.