Advertisement

question on classes

Started by April 01, 2001 06:30 PM
3 comments, last by omegasyphon 23 years, 10 months ago
ok how would i access the arrays in this class?
  
class maze
{
	int datamap[10][10];
	int map[30][30];
public:
	maze();
	void randomizemaze(int [][10],int);
	void printmaze(int [][10],int);
};
  
if my object is named maze1 why doesnt this work maze1.datamap [sourc] maze1.randomizemaze(maze1.datamap,10); [/source]
I believe that datamap and map are both private members of the class. This means that you cannot directly access it outside the class.

To do this, you could write a member function (make sure it''s a public function) that returns your datamap / map arrays.
Advertisement
By default, class members are private. You could write an access method, as suggested above, or just make them public.

~~~~~~~~~~
Martee
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
so is this right because i get an access violation when i run it


  void maze::initvar(int *ary[][10],int r1,int *ary2[][30],int r2){	datamap[r1][10] = *ary[r1][10];	map[r2][30] = *ary2[r2][30];}  
ok this is the most complex crap with classes to get working,

now if the following is correct which i assume it is
how would i tell my function to utilize datamap and map like so


  maze::maze(){	datamap[10][10] = {{0},{0}};	map[30][30] = {{0},{0}};}maze::~maze(){}int maze::getdatamap(){	return datamap;}int maze::getmap(){	return map;}void maze::randomizemaze(){	int num,x,y;	for (x=0;x<10;x++)	{		num = (rand()% 13) +1;		if (num==1 || num==4 || num==6 || num==7 || num==10 || num==14)			datamap[0][x]=num;		if (num==1 || num==2 || num==3 || num==5 || num==8 || num==14)			datamap[9][x]=num;	}	for (x=1;x<9;x++)	{		for (y=1;y<9;y++)		{			num = (rand()%13) + 1;			while (num != 1 || num != 2 || num !=3 || num!=4)				datamap[y][x]=num;		}	}	for (y=1;y<9;y++)	{		num = (rand ()% 13) +1;		if (num==1 || num==2 || num==4 || num==5 || num==6 || num==9 || num==13)			datamap[y][1] = num;		if (num==2 || num==3 || num==4 || num==7 || num==11 || num==13)			datamap[y][8] = num;	}}  


This topic is closed to new replies.

Advertisement