expected initializer before ‘&’ token

I get the error "expected initializer before ‘&’ token" when compiling

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const organsim_cell &organisms::operator[] (int i)    // access organism_cell at postion i
{



	if ((i>=0) && (i<num_cells)) 
	{

		return orgs[i];

	}

	else    // this is an error
	{

		cout << "Index out of range in organisms::operator[]()" << endl;

		cout << "Exiting" << endl;

		exit( );

	}

	return NULL;

}


As well, here is the header....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class organisms 
{

	organism_cell orgs[MAX_CELLS]; // at most MAX_CELLS organisms will be present 

	int num_cells;		       // number of organism cells in use (determined

				       //           while reading input file)

public:

	organisms( );		   // sets all organism cells to be dead

	organisms(int size);       // sets num_cells and makes all organisms dead



	void set_size(int size);   // change the size of the row



	organism_cell &operator[](int i);  // access organism_cell at postion i

	const organisms &operator=(const organisms &O); // make row equal to that of O

	bool operator==(const organisms &O);  // check if rows are equal

};


So...yeah, thanks for the help ^^
Did you mean to write "organsim" on line 1 of the source?

This also assumes that organism_cell has been previously defined.
Last edited on
Topic archived. No new replies allowed.