Array must not exceed

Hello everyone I keep getting this array must not exceed error but all I trying to create is a 20 x 20 array of objects. It does the same with objects and templates.
The reason I am using an array and not a vector is because I need a constant 20 x 20 container for my game board. And from what i think I know vectors re-size them self's every time some thing is removed or added. Please let me know where I went wrong Thank you very much.

Edit: Why can I put this line: 'Organism temp[20][20];'
in main and have no issues.

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  #ifndef GAMEBOARD_H
#define GAMEBOARD_H

#include "Location.h"
#include "stdafx.h"

template<class T>
class GameBoard
{
public:
	GameBoard( );
	bool postionIsOcuppied(Location& postion, T& player);
	void addPlayer2Board(T& player);
	void removePlayerFromBoard(Location& postion);
	T& getPlayerFromBoard(int x, int y);
	bool postionContainsAnt(Location& postion);
	bool postionContainsDoodleBug(Location& postion);

private:
	T _gameBoard[20][20]; //<-- Problem

};

template<class T>
GameBoard<T>::GameBoard( ) 
{
	for(int i =0; i < 20; i++)
	{
		for(int j =0; j < 20; j++)
		{
			_gameBoard[i][j] = T;
		}
	}
}

template<class T>
bool GameBoard<T>::postionIsOcuppied(Location& postion, T& player)
{
	return _gameBoard[postion.getXPoint( )][postion.getYPoint( )].getSpecies( ) == 'A' ||
		_gameBoard[postion.getXPoint( )][postion.getYPoint( )].getSpecies( ) == 'D';
}

template<class T>
bool GameBoard<T>::postionContainsAnt(Location& postion)
{
	return _gameBoard[postion.getXPoint( )][postion.getYPoint( )].getSpecies( ) == 'A';

}

template<class T>
bool GameBoard<T>::postionContainsDoodleBug(Location& postion)
{
	return _gameBoard[postion.getXPoint( )][postion.getYPoint( )].getSpecies( ) == 'D';
}

template<class T>
void GameBoard<T>::addPlayer2Board(T& player)
{
	_gameBoard[player.getLocation().getXPoint( )][player.getLocation().getYPoint( )] = player;
}

template<class T>
void GameBoard<T>::removePlayerFromBoard(Location& postion)
{
	_gameBoard[postion.getXPoint()][postion.getYPoint()] = T( ); 
}

template<class T>
T& GameBoard<T>::getPlayerFromBoard(int x, int y)
{
	return _gameBoard[x][y]; 
}
#endif //GAMEBOARD_H

#ifndef ORGANSIM_H
#define ORGANSIM_H

#include "location.h"
#include <iostream>
#include "GameBoard.h"

class Organism	
{
public:
	Organism( );
	Organism(Location postion, int times, bool breed, char species);
	Organism(const Organism& other);
	Organism& operator=(const Organism& other);
	friend std::ostream& operator<<(std::ostream& out, Organism& rg2Write);
	bool getBreed( ) const;
	void setBreed(const bool breedOrNot);
	int getMovementsTillBreed( ) const;
	virtual Location& getLocation( );
	virtual void setLocation(const int x, const int y);
	void setMovementsTillBreed(int times);
	virtual char getSpecies( ) { return _species; } 
	virtual void move( ); 
	virtual int calculateDirection( ) ;

private:	
	//Location _points;
	int _movementsTillBreed;
	bool _breed;
	char _species;
	GameBoard<Organism> _gameBoard; //<--- Where it is created
	

protected:
	Location _points;
};

#endif // ORGANSIM_H 


here is the error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
:\users\adam\skydrive\c++_projects\chapter_15\exercise_03\exercise_03\gameboard.h(20): error C2148: total size of array must not exceed 0x7fffffff bytes
1>          d:\users\adam\skydrive\c++_projects\chapter_15\exercise_03\exercise_03\organsim.h(32) : see reference to class template instantiation 'GameBoard<T>' being compiled
1>          with
 [
1>              T=Organism
1>          ]
1>d:\users\adam\skydrive\c++_projects\chapter_15\exercise_03\exercise_03\gameboard.h(20): error C2079: 'GameBoard<T>::_gameBoard' uses undefined class 'Organism'
1>          with
1>          [
1>              T=Organism
1>          ]
1>  Exercise_03.cpp
1>d:\users\adam\skydrive\c++_projects\chapter_15\exercise_03\exercise_03\ant.h(9): error C2504: 'Organism' : base class undefined
1>  Ant.cpp
1>d:\users\adam\skydrive\c++_projects\chapter_15\exercise_03\exercise_03\ant.h(9): error C2504: 'Organism' : base class undefined
1>d:\users\adam\skydrive\c++_projects\chapter_15\exercise_03\exercise_03\ant.cpp(10): error C2614: 'Ant' : illegal member initialization: 'Organism' is not a base or member
1>d:\users\adam\skydrive\c++_projects\chapter_15\exercise_03\exercise_03\ant.cpp(19): error C2653: 'Organism' : is not a class or namespace name
1>d:\users\adam\skydrive\c++_projects\chapter_15\exercise_03\exercise_03\ant.cpp(24): error C2653: 'Organism' : is not a class or namespace name
1>d:\users\adam\skydrive\c++_projects\chapter_15\exercise_03\exercise_03\ant.cpp(25): error C2653: 'Organism' : is not a class or namespace name
1>d:\users\adam\skydrive\c++_projects\chapter_15\exercise_03\exercise_03\ant.cpp(32): error C2065: '_points' : undeclared identifier
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
Line 20: What is the definition of _gameBoard ?

You're trying to declare an array of 400 _gameBoards which the compiler is telling you exceeds 0x7fffffff bytes.
Last edited on
I am trying to create a array of type T which I want to be Organism.
Last edited on
Here's your problem:

- GameBoard has an array of T's
- Organism has a gameboard of Organisms.
- This effectively means that each Organism has an an array of organisms.
- Which means that each of the organisms in that array has its own array
- and each organism in that array has yet another array
- etc etc
- as a result organisms are infinitely large and cannot be instantiated.


This is a design problem. Each organism should not have their own game board, but should have a pointer/reference to a game board owned by some other part of the program.
I see. Thank you .
Last edited on
Topic archived. No new replies allowed.