weird segmentation fault
<p>What I have been doing is a reverse polish notation calculator.I have met this error when compiling my program below:</p>

<pre><code>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-&gt;evaluate()+x2-&gt;evaluate());
                 string x;
                 x.append(x2-&gt;getExp());
                 x.append("+");
                 x.append(x1-&gt;getExp());
                 setExp(x);
                }
             else if(op=="-"){
                 setValue(x1-&gt;evaluate()-x2-&gt;evaluate());
                 string x;
                 x.append(x2-&gt;getExp());
                 x.append("-");
                 x.append(x1-&gt;getExp());
                 setExp(x);
                }
             }
 };
</code></pre>

<p>then in my main function:</p>

<pre><code> 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&lt;10;i++) stack[i]=NULL;
  ...
  string s_input;
  getline(cin,s_input);
  istringstream sss(s_input);

  while(!sss.eof() &amp;&amp; p&gt;-2){
  sss&gt;&gt;s;
  if(s=="+" || s=="-")
     binary *b = new binary;
     b-&gt;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&gt;&gt;temp;
     c-&gt;setValue(temp);
     stack[p]=c;
     p--;
  }
  }
  ...
</code></pre>

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

<p>PLUS:p would not overrun in this case.</p>
