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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:28:53+00:00 2026-06-14T10:28:53+00:00

void PDA::parse(vector<string> words){ for(int i=0; i<words.size();i++){//for each string in the input file string token=words[i];

  • 0
  void PDA::parse(vector<string> words){
    for(int i=0; i<words.size();i++){//for each string in the input file
    string token=words[i];
    for(int j=0; j<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<<"The string "<<words[i]<<" is balanced and was accepted"<<endl : cout<<"The string "<<words[i]<<" is not balanced and was not accepted"<<endl;
}
}

I’m getting these errors

PDA.cpp:25: error: no match for âoperator[]â in â((PDA*)this)->PDA::stack[j]â
PDA.cpp:26: error: no match for âoperator[]â in â((PDA*)this)->PDA::stack[(j - 1)]â

for these lines

if(!stack[j]){//since j-1 when the index is 0 will cause an error
              if(stack[j-1]==matchingBracket){

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.

#ifndef PDA_H
#define PDA_H
#include <stack>
#include <vector>
#include <deque>
class PDA{
 private:
  std::stack<char> stack;
 public:
  PDA();
  bool isEmpty();
  void parse(std::vector<std::string>);
  char getMatchingBracket(char);
  bool accepted();
};
#endif

As I see it, using operator[] on a std::stack should work just fine. Any ideas?

  • 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-14T10:28:54+00:00Added an answer on June 14, 2026 at 10:28 am

    std::stack doesn’t inherit from the underlying container type, it adapts it to a completely new interface. The underlying container is not exposed. That’s essentially the point of the adaptors std::stack and std::queue: they ensure that you’re using a more limited interface that will be the same regardless of the underlying structures.

    That said, you can inherit from std::stack and access the underlying container from a subclass. It is a protected member named c.

    class my_stack : public std::stack< char > {
    public:
        using std::stack<char>::c; // expose the container
    };
    
    int main() {
        my_stack blah;
        blah.push( 'a' );
        blah.push( 'b' );
        std::cout << blah.c[ 1 ]; 
    }
    

    http://ideone.com/2LHlC7

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

Sidebar

Related Questions

void slice_first_char(char ** string) { *string = &(*string[1]); } int main(int argc, char *
void display(char * str){ printf(%s: Missing file\n, str); } int main(int argc, char **argv)
void gctinp (char *inp, int siz) { puts (Input value: ); fgets (inp, siz,
void foo(Node* p[], int size){ _uint64 arr_of_values[_MAX_THREADS]; for (int i=0 ; i < size
void AFCQueue::ExtractValuesSecComplex(int startIndex, int endIndex,int helperIndex) { int size = 0,i,index; TimeType min_timestamp; bool
void swap(int a[], int size){ ............... } int main(){ int x[4] = {4,5,3,12} ;
void max_min(sqlite3 *db) { //call back********* int i, ncols; sqlite3_stmt *stmt; char *sql; const
void foo(char *p) { int i; int len = strlen(p); p = malloc(sizeof(char)*len+2); p[0]
void func(const std::string& args) { // Statically initialize a vector of lambdas (only one
void testFunc(int); int main(int argc, char** argv) { testFunc(1); testFunc(2); testFunc(3); return (EXIT_SUCCESS); }

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.