Advertisement

help!!!

Started by December 10, 2002 09:13 AM
1 comment, last by kappa the imp 21 years, 11 months ago

  
class FourRow
{
public:
	FourRow():GameLoop(true){}

	void CleanArray()
		{
		for(int y = 0; y<10; y++)
			for(int x = 0; x<10; x++)
			Array[x][y] = 0;
		}
	
	void DrawBoard();
	bool GetPlayerInput();
	bool CheckIfWon();	
	
protected:
	bool GameLoop;
        char Array[10][10];
    
};
//AI.h

class AI : public FourRow
{
public:
	AI(){}
	
    void DrawOnBoard();
	void Think();
	void Speak(int Line);
	
private:
	int AIArray[10][10];
        int AIx;
	int AIy;
};
  
I need help, What I whant is to acces the Array variable with all its values in the AI class, What happens is that the Array doesnt have its values left in it when I try to access it from a function in the AI class.
I don''t know exactly what you mean by that but i guess you have something like this:


  FourRow Player;AI      Computer;  


If you access Computer.Array it is completely normal that it is empty, even though you filled the data up in Player. Player and Computer are 2 different instances of the FourRow class, thus they are not sharing data. This can be done by making Array static:


  // Previous stuffprotected:   static char Array[10][10];// Access the array from within any instance of the class:FourRow::Array[X*Y] = ''X'';  


Now you can access Array also from the AI class as I showed.

Hope this helped,

Sand Hawk

----------------
-Earth is 98% full. Please delete anybody you can.


My Site
----------------(Inspired by Pouya)
Advertisement
thank you , but now I get this error
[linker error]undefined reference to ''FourRow::Array''
(its in dev)

This topic is closed to new replies.

Advertisement