Comp Sci Template for STL in .h File: Error Fix

  • Thread starter Thread starter anonim
  • Start date Start date
  • Tags Tags
    C++
AI Thread Summary
The discussion focuses on a template class definition in a header file, specifically addressing an error related to the declaration of a member variable. The error message indicates that 'T' is not recognized as a template, suggesting that the template parameter 'T' is incorrectly used in the line declaring 'Board'. Participants highlight the need to ensure that 'T' is properly defined as a template type before its usage. The conversation emphasizes the importance of correct template syntax and initialization within the class. Clarifying the template declaration should resolve the encountered error.
anonim
Messages
39
Reaction score
2
Homework Statement
BAdapter: This class takes a template parameter and behaves like an adaptor class just like the stack or queue class of the STL. The parameter classes can be any STL class with a random access iterator.
Relevant Equations
-
in .h file I write like this:

C++:
namespace board{
    template <class T>
    class BAdapter : public AbstractB{
        public:
            BAdapter();
            BAdapter(int x){
                x=6;
                setSize(x);
            }
            virtual void setSize(int receivedSize){
                int i,j;
                Board.clear();
                size=receivedSize;
                Board.resize(getSize());
                for(i=0; getSize()>i; i++){
                    Board[i].resize(getSize());
                }
                reset();
            }
      
            virtual bool loadGame(string fileName,char player,int game_mode){
                fstream file;
                int size2;
                int i,j;
                string line;
                bool flag=false;
                char state;

                file.open(fileName);
        
                if(file.is_open()){
                    file>>size2;
                    file>>player;
                    Board.clear();
                    Board.setSize(size2);
                    for(i=0; size2>i; i++){
                        file>>line;
                        for(j=0; size2>j; j++){
                            if(line[j]=='.'){
                                state='.';
                            }
                            else if(line[j]=='x'){
                                state='x';
                            }
                            else if(line[j]=='o'){
                                state='o';
                            }
                            Board[i][j].setRow(i);
                            Board[i][j].setColumn(j);
                            Board[i][j].set_cellState(state);
                        }
                    }
                    flag=true;
                    size=size2;

                    file.close();
                
                }
                 return flag;
            }
        protected:
            T<T<char>>Board;

    };
}

Actually, I did not understand exactly what I was expected to do, but I get an error.
Error is:
‘T’ is not a template
T<T<char>>Board;
 
Last edited by a moderator:
Physics news on Phys.org
Maybe declare T somewhere?
 

Similar threads

Replies
2
Views
2K
Replies
5
Views
3K
Replies
23
Views
8K
Replies
2
Views
5K
Replies
1
Views
2K
Replies
3
Views
2K
Back
Top