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

  • SEARCH
  • Home
  • 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 6828261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:21:44+00:00 2026-05-26T22:21:44+00:00

What I have been doing is a reverse polish notation calculator.I have met this

  • 0

What I have been doing is a reverse polish notation calculator.I have met this error when compiling my program below:

class Expression {
       protected:
                 string exp;
                 int value;
       public:
                 void getExp();//extract the exp from Expression
                 void setExp(string s);//store s in Expression
                 void setValue(int n);//store n in Expression
                 int evaluate();//extract the value from Expression
 };


 ...
 class binary : public Expression {
  public:
          void binaryyy(Expression *x1,Expression *x2,string op){
             if(op=="+"){
                 setValue(x1->evaluate()+x2->evaluate());
                 string x;
                 x.append(x2->getExp());
                 x.append("+");
                 x.append(x1->getExp());
                 setExp(x);
                }
             else if(op=="-"){
                 setValue(x1->evaluate()-x2->evaluate());
                 string x;
                 x.append(x2->getExp());
                 x.append("-");
                 x.append(x1->getExp());
                 setExp(x);
                }
             }
 };

then in my main function:

 int main(){
  ...
  Expression *stack[10];
  int p=9,i;//p refers to one slot above the top element of the stack
  for(i=0;i<10;i++) stack[i]=NULL;
  ...
  string s_input;
  getline(cin,s_input);
  istringstream sss(s_input);

  while(!sss.eof() && p>-2){
  sss>>s;
  if(s=="+" || s=="-")
     binary *b = new binary;
     b->binary(stack[p+1],stack[p+2],s);
     stack[p+1]=NULL;
     stack[p+2]=b;
     p++;
  }
  else if(s.isNumber())//s.isNumber() might not exist.it means that s is number...
  {
     Expression *c=new Expression;
     istringstream ss(s);
     int temp;
     ss>>temp;
     c->setValue(temp);
     stack[p]=c;
     p--;
  }
  }
  ...

I have checked very carefully for any possible illegal allocation or call of memory slots and all.NO CLUE…

PLUS:p would not overrun in this case.

  • 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-26T22:21:45+00:00Added an answer on May 26, 2026 at 10:21 pm
    int p=9,i;//p refers to the top of the stack
    
    ...
    
    b->binary(stack[p+1],stack[p+2],s);
    stack[p+1]=NULL;
    stack[p+2]=b;
    

    Well there is an overrun. stack[p+1] is stack[10] and stack[p+2] is stack[11] in your ten element array. You’re writing past the bounds of your array (unless the ... contains code which adjusts p correctly, but I have no way to know).

    After that problem is fixed you need to initialize your stack array. Currently you have an array of 10 pointer to Expression. None of them are initialized to point to anything valid though, and you later dereference them.

    Also…

    b->binary(...)
    

    Won’t compile.

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

Sidebar

Related Questions

I have been doing research on HTML canvas libraries and I came across this
I have been doing some customization to this jQuery paging script I found here
I have been doing some reading on this subject, but I'm curious to see
I have been doing this: public List<Role> GetRoles() { List<Role> result = new List<Role>();
I have been doing a lot of research trying to figure this out, but
I have been doing some research about this and have found a few similar
I have been doing this research for 2 days now, but i cant seem
I have been doing some research on the correct procedure to follow when working
I have been doing a phonegap app for android but am stuck on the
I have been doing some testing with the following code to try and work

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.