Hai everybody!I'm trying to implement a program to implement Quine McCluskey algoritm.While trying to compile with the following code,I got an error which says " no match for 'operator[]' in '((Table*)this)->Table::isMarked[r]' " .

Attached are the files: Table.h,Table.cpp,Term.h,Term.cpp

Please help!!!

Attachments
#include"Table.h"
#include<iostream>
using namespace std;
Table::Table(set<Term> imp, set<int> min)
{
   implicants = imp;
   minterms = min;
   
   rowsize = min.size();
   colsize = imp.size();
   
   isMarked = new bool* [ colsize ];
   for(int c = 0; c < colsize; c++)
    isMarked[ c ] = new bool[ rowsize ];
   
   int r,c; 
   for(set<Term>::iterator it_imp = imp.begin(), r = 0
                           ;it_imp != imp.end()
                           ;it_imp++, r++)
   {   
      set<int>::iterator it_tg = (*it_imp).termsGrouped.begin();    
      for(set<int>::iterator it_min = min.begin(), c = 0
                             ;it_min != min.end()
                             ;it_min++, c++)
      {
        if(*it_tg == *it_min)
         isMarked[r][c] = true;
        else
         isMarked[r][c] = false;
        
        if(*it_tg <= *it_min)
         it_tg++;
      }
   }
}

void Table::deleteImplicant(int cpos)
{
   implicants.erase( getImplicant(cpos) );
   
   for(int c = cpos+1; c<colsize; c++)
    for(int r = 0; r<rowsize; r++)
     isMarked[ r ][ c-1 ] = isMarked[ r ][ c ];
    
   if( colsize>0 )
    colsize--;
}

void Table::deleteMinterm(int rpos)
{
   minterms.erase( getMinterm(rpos) );
   
   for(int r = rpos+1; r<rowsize; r++)
    for(int c = 0; c<colsize; c++)
     isMarked[ r-1 ][ c ] = isMarked[ r ][ c ];
    
   if( rowsize>0 )
    rowsize--;
}
 
Term Table::getImplicant(int cpos)
{
   set<Term>::iterator it_imp = implicants.begin();
   
   while( cpos>0 )
   {
     it_imp++;
     cpos--;
   }
   
   return *it_imp;
}
     
int Table::getMinterm(int rpos)
{
   set<int>::iterator it_min = minterms.begin();
   
   while( rpos>0 )
   {
     it_min++;
     rpos--;
   }
   
   return *it_min;
}
     
void Table::display()
{
   cout<<"      ";
   for(set<int>::iterator it_min  = minterms.begin()
                         ;it_min != minterms.end() 
                         ;it_min++)
   {
      cout.width(2);
      cout<<*it_min<<" ";
   }
   
   set<Term>::iterator it_imp = implicants.begin();
   for(int r = 0; r<rowsize; r++)
    for(int c = 0; c<colsize; c++)
       if( isMarked[ r ][ c ] )
       {
          cout.width(2);
          cout<<"X"<<" ";
       }
}

Table::~Table()
{
   for(int c = 0; c < colsize; c++)
    delete isMarked[c] ;
   
}
#ifndef TABLE_H
#define TABLE_H

#include"Term.h"
class Table
{
   set<Term> implicants;
   set<int>  minterms;
   public:
          bool** isMarked;
          int rowsize;
          int colsize;
          Table(set<Term>, set<int>);
          
          void deleteImplicant(int);
          void deleteMinterm(int);
          Term getImplicant(int);
          int getMinterm(int);
          void display();
          
          ~Table();
};

#endif
#include"Term.h"
#include<iostream>
#include<stack>
#include<cstring>

using namespace std;
/*
Term(const Term& term)  // Copy constructor.
{
   value = term.value;
   termsGrouped = term.termsGrouped;
   positionsCovered = term.positionsCovered;
} 
*/
Term::Term(int val)
   {
      value = 0;
      groupTerm( val );
   }

void Term::coverPosition(int val)
   {
    positionsCovered.insert( val );
   }
    
void Term::groupTerm(int val)
   {
    termsGrouped.insert( val );
    if(value < val) value = val; 
   }
   
void Term::printTerm(char arr[][5])
{
     stack<char*> result;
     int cnt = 0;
     set<int>::iterator it_pc = positionsCovered.begin();

     while(value)
     {
        if(cnt != *(it_pc))
        {
           if( value%2 )
            result.push( arr[cnt] );
           else
            result.push( strcpy(arr[cnt], "'") );
           value = value / 2;
        }
        else if(it_pc != termsGrouped.end())
            cnt++;
     }
     
     while( !result.empty() )     
     {       
        cout<<result.top();        
        result.pop();
     }
}
     
bool operator < (const Term& left, const Term& right)
{
     set<int>::iterator it_left_tg;
     set<int>::iterator it_right_tg;
     
     for(it_left_tg = left.termsGrouped.begin(),
         it_right_tg = right.termsGrouped.begin()
                   ;it_left_tg != left.termsGrouped.end()
                   ;it_left_tg++, it_right_tg++)
     {
        if(*it_left_tg > *it_right_tg)
         return false;
     }
     //Execution reaches here iff left<right.
     return true;
}
#ifndef TERM_H
#define TERM_H
#include <set>     //An STL.
using std::set;

class Term
{
      public:
              int value;                 
                       
              set<int> termsGrouped;   
              set<int> positionsCovered;
             
              Term();
              Term(int);
              void coverPosition(int);   
              void groupTerm(int);
              void printTerm(char[][5]);
};
bool operator < (const Term& left, const Term& right); // Must be defined for properdefinition of set.
#endif

I don't see that expression used in the files you've attached.

Shouldn't it be ((Table*)this)->Table::isMarked[r][c] ?

In the file Term.cpp line numbers 24 and 25 I have used 'isMarked[r][c]' and the error is occuring in these lines.

My problem is solved! Infact,I am using Dev cpp IDE.The compiler didn't recognise the 'c = 0 and 'r = 0' int the 'for' loops.If you notice,the same statement 'isMarked[r][c]' is not creating problem in any other part of the code.Anyway tons of thanks for your suggestion!!!It gave me the clue!

Glad you found the problem.

Still, I don't see the isMarked[r][c] in the term.cpp file you provided. You sure we're all looking at the same thing?

OK, with you now. Odd that the initialization in the for statement caused a problem, it should work. And it doesn't seem to jibe with the error message you report.

How'd you fix it?

Instead of doing the initialisation 'r = 0' in the 'for' loop I gave it seperately.I think problem was with the compiler that comes bundled with Dev-C++ (MingW32).

This question has already been answered. Start a new discussion instead.