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 7774119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:17:56+00:00 2026-06-01T17:17:56+00:00

I have to write these two methods, to print out what is contained within:

  • 0

I have to write these two methods, to print out what is contained within:

ex is an array composed tokenType tk (sorry, trying to save space and avoid posting the whole structs)

Unfortunately, I am getting a compile error that says: error: no match for âoperator[]â in âex[i]â

How can I fix this so it will override <<, so that the second method uses the first?

ostream & operator<< ( ostream & os , const tokenType & tk)
{
    switch (tk.category)
    {
            case TKN_OPRAND:
            os << tk.operand;
            break;
            case TKN_OPRTOR:
            os << tk.symbol;
            break;              
    }
    return os;
}

ostream & operator<< ( ostream & os , const expression & ex)
{   
    tokenType tk;

    for (int i = 0; i < ex.numTokens; i++)
    {
        tk = ex[i];
        os << tk.operand << " ";  //problem line is this one
    }   
    return os;  
}

struct expression
{
    int numTokens ;
    tokenType tokens[MAX_TOKENS_IN_EXPRESSION] ;
    void print() const ;
    int  toPostfix( expression & pfx ) const ;
    int  evalPostfix( int & val ) ;
    expression() { numTokens = 0 ; } ;  // default constructor
} ;
  • 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-06-01T17:17:57+00:00Added an answer on June 1, 2026 at 5:17 pm

    You are very close – you forgot to reference the tokens array, and tried indexing the expression itself. Naturally, the compiler complained, because you do not have a [] overloaded.

    This should work:

    for (int i = 0; i < ex.numTokens; i++)
    {
        tk = ex.tokens[i]; // <<==== Here is the fix
        os << tk.operand << " ";
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a better to write the following? I have two services that I
I am trying to check if I have write access to a specific key
In a LaTeX report I am making I have to write a regex. There
I have users who write articles and when they leave there computer for a
There have been questions with answers on how to write rubygems, but what should
I have a few Silverlight UI tests that I'm automating with White. These tests
So, there is problem - I have the order to write web-app on Kohana
We have 10 Linux boxes that must run 100 different tasks each week. These
I'm trying to figure out if what I want to do is even possible.
At the end of my computations, I print results: System.out.println(\nTree\t\tOdds of being by 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.