title: Trying to access an index of an std::stack
body: <pre><code>  void PDA::parse(vector&lt;string&gt; words){
      for(int i=0; i&lt;words.size();i++){//for each string in the input file
      string token=words[i];
      for(int j=0; j&lt;token.length(); j++) //for each character in the string
        {
          char input=token[j];
          char matchingBracket=getMatchingBracket(input); //returns the matching bracket, should probably just have ( and [
  
          if(!stack[j]){//since j-1 when the index is 0 will cause an error
            if(stack[j-1]==matchingBracket){
              stack.pop();
            }else{
              stack.push(input);
            }
  
          }
    }
      accepted()?cout&lt;&lt;"The string "&lt;&lt;words[i]&lt;&lt;" is balanced and was accepted"&lt;&lt;endl : cout&lt;&lt;"The string "&lt;&lt;words[i]&lt;&lt;" is not balanced and was not accepted"&lt;&lt;endl;
  }
  }
  </code></pre>
  
  <p>I'm getting these errors</p>
  
  <pre><code>PDA.cpp:25: error: no match for âoperator[]â in â((PDA*)this)-&gt;PDA::stack[j]â
  PDA.cpp:26: error: no match for âoperator[]â in â((PDA*)this)-&gt;PDA::stack[(j - 1)]â
  </code></pre>
  
  <p>for these lines</p>
  
  <pre><code>if(!stack[j]){//since j-1 when the index is 0 will cause an error
                if(stack[j-1]==matchingBracket){
  </code></pre>
  
  <p>I looked up std::stack and found out that "By default, if no container class is specified for a particular stack class, the standard container class template deque is used." When I looked up deque I found out it supports operator[]. This is how I declared my stack. In the corresponding header file to this source file.</p>
  
  <pre><code>#ifndef PDA_H
  #define PDA_H
  #include &lt;stack&gt;
  #include &lt;vector&gt;
  #include &lt;deque&gt;
  class PDA{
   private:
    std::stack&lt;char&gt; stack;
   public:
    PDA();
    bool isEmpty();
    void parse(std::vector&lt;std::string&gt;);
    char getMatchingBracket(char);
    bool accepted();
  };
  #endif
  </code></pre>
  
  <p>As I see it, using operator[] on a std::stack should work just fine. Any ideas?</p>