Getting an undeclared identifier error in my program

This is a discussion on Getting an undeclared identifier error in my program within the C++ Programming forums, part of the General Programming Boards category; hi this program is supposed to be able to play tic-tac-toe... but in my .cpp file I keep getting this ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    2

    Getting an undeclared identifier error in my program

    hi this program is supposed to be able to play tic-tac-toe... but in my .cpp file I keep getting this error "cpp(19) : error C2065: 'Board' : undeclared identifier"

    can anyone see whats going on?

    thanks guys
    Code:
    //FileName: GameBoard.h
    #include <iostream>
    #include <string>
    
    #ifndef GAMEBOARD_H
    #define GAMEBOARD_H
    
    class GameBoard
    {
    	private:       
            char Board[3][3];
    
    	public:
    		GameBoard();
    		void setSquare(char symbol, int r, int c){Board[r][c]=symbol;}
    		char getSquare(int r, int c) {return Board[r][c];}
    		int haveWinner();
            void makeComputerPlay(int &row, int &col);
    					
    };
    #endif
    Code:
    #include <GL\glut.h>
    #include "GameBoard.h"
    
    GameBoard::GameBoard()
    {
    
    	for (int r=0; r<3; r++)
    	{
    		for(int c=0; c<3; c++)
    		{
    			Board[r][c]=' ';
               
    		}
    	}
    }
    
    char haveWinner()
    {
    			if (Board[0][0]==Board[0][1]&& Board[0][1]==Board[0][2]&&Board[0][0]!=' ')
    			{
    				return Board[0][0];
    			}
    			else if(Board[1][0]==Board[1][1]&&Board[1][1]==Board[1][2]&&Board[1][1]!=' ')
    			{
    				return Board[1][0];
    			}
    			else if(Board[2][0]==Board[2][1]&&Board[2][1]==Board[2][2]&&Board[2][2]!=' ')
    			{
    				return Board[2][0];
    			}
    			else if(Board[0][0]==Board[1][0]&&Board[1][0]==Board[2][0]&&Board[0][0]!=' ')
    			{
    				return Board[0][0];
    			}
    			else if(Board[0][1]==Board[1][1]&&Board[1][1]==Board[2][1]&&Board[0][1]!=' ')
    			{
    				return Board[0][1];
    			}
    			else if(Board[0][2]==Board[1][2]&&Board[1][1]==Board[1][2]&&Board[0][1] !=' ')
    			{
    				return Board[0][2];
    			}
    			else if(Board[0][0]==Board[1][1]&&Board[1][1]==Board[2][2]&&Board[0][0]!=' ')
    			{
    				return Board[0][0];
    			}
    			else if(Board[2][2]==Board[1][1]&&Board[1][1]==Board[2][2]&&Board[2][2]!=' ')
    			{
    				return Board[2][2];
    			}
    
    			return ' ';
    
    }
    
    void makeComputerPlay(int &row, int &col)
    {
        
    	if(Board[1][1]==' ') //middle square
    	{
    		Board[1][1] = 'O';
    		row = 1;
    		col = 1;
    	}
    	
        if(Board[0][0]==' ') //upper left
    	{
    		Board[0][0] = 'O';
    		row = 0;
    		col = 0;
    	}
    	if(Board[2][0]==' ')//lower lef
    	{
    		Board[2][0] = 'O';
    		row = 2;
    		col = 0 ;
        }
    	if(Board[0][2]==' ')//upper right //&&Board==[2][0]
    	{
    		Board[0][2]='O';
    		row = 0;
    		col =2 ;
    	}
    	if(Board[2][2])// lower middle
    	{
    		Board[2][2]='O';
    		row = 2;
    		col = 2;
    	}
       
    }

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    char haveWinner() has no access to any variable named Board...


    in your header file you declared something called 'int haveWinner();'

    but in your cpp you have char haveWinner, and you didnt declare how -i think- you intended

    try using these, i think this is what you meant maybe.

    Code:
    char GameBoard::haveWinner()
    Code:
    void GameBoard::makeComputerPlay(int &row, int &col)
    and don't forget to correct the header file from char to int if thats what you intend

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2
    Thank you so much.. I really appreciate it.. I knew it would be something that I was over looking.. thanks again. it works now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-16-2009, 07:00 AM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 11:17 AM
  3. Declared identifier reported as undeclared
    By yougene in forum C Programming
    Replies: 3
    Last Post: 08-22-2006, 10:07 PM
  4. Undeclared Identifier
    By Kayoss in forum C++ Programming
    Replies: 2
    Last Post: 04-08-2006, 11:48 AM
  5. Maximizing a Console Window Full Screen
    By philvaira in forum Windows Programming
    Replies: 10
    Last Post: 08-13-2004, 03:27 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21