C++ E0413 I want pushback with a Pointer


Hi i have problem with my code.
I want use pushBack with a Pointer.

But when i use it E0413 appears.

How i can fix this.

I dont want use vector beacuse its destroys everthing.

I can^'t use with vector it destroys the code on Main.cpp
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
void MapLoader(const char * fname,int Map [1340][1340])
{
	
	
	ifstream in(fname, ios::in);
	int dataholder;
	while (in >> dataholder) {
		//Add the number to the end of the array
		Map.push_back(dataholder);
		
	}
	
	in.close();
}


void MapGen(int    Map[1340][1340])
{

	for (int i = 0; i < 10; i++)
	{

		for (int j = 1; j < 10; j++)
		{
			if(Map[i][j] == 1) {
			glPushMatrix();
			glTranslatef(j, -i, 0);
			drawBox();
			glPopMatrix();
		}
		}
	}
	for (int i = 0; i < 10; i++)
	{

		for (int j = 0; j < 10; j++)
		{
			if (Map[i][j] == 0) {
				glPushMatrix();
	
			glPopMatrix();
			}
		}

	}
}



You can't use push_back for a fixed-size array (by definition). Also not clear what pushing back to a 2-dimensional array even means.

BTW how have you declared that array in the calling routine? It's going to be very big to go on the stack.
standard (C) arrays do not have ANY methods. They are nothing more than an access entry point to raw memory.
Map is a type in c++ and may be confusing to use as a variable name.

you can load an array like this:
int dx = 0;
while (in >> MAP[0][dx++] ) ; //no need for dataholder, it is redundant, read directly into the thing.

if your input file has 2,4,6,8 then
map[0][0] is 2, map[0][1] is 4, and map[0][3] is 8.
I have no idea what your 2-d means so I don't know how you want to control the rows and columns as you load data in.

if the file does not fill the array you can track that dx value to know how many you have and where to insert next if you get more. You must do this yourself.

vectors do not destroy anything unless you code it to do so; you have misused or misunderstood the tool. look at the keyword static if you need one to live longer than its scope. Vectors are superior arrays and should be used unless you have a better reason (your reason indicates a problem with you or your code).
Last edited on
> I dont want use vector beacuse its destroys everthing.
> I can^'t use with vector it destroys the code on Main.cpp
Perhaps it would be better to FIX your broken understanding of the language, rather than regress into the primordial soup of arrays.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Not a copy of a map, a reference to the actual map in main
void MapLoader(const char * fname, vector<int> &Map)
{
	ifstream in(fname, ios::in);
	int dataholder;
	while (in >> dataholder) {
		//Add the number to the end of the array
		Map.push_back(dataholder);
	}
	// unnecessary with RAII in.close();
}

int main ( ) {
	vector<int> myMap;
	mapLoader("file.txt",myMap);
}
Topic archived. No new replies allowed.