double pointer help



1
2
3
4
5
6
7
8
9
10
	mapprinter = new (nothrow) char [mapxc*mapyc+mapyc];
			if (mapprinter==0){
		cout << "error";
		}
	for(int i=0;i<mapyc;i++){
		map[i] = new (nothrow) char [mapxc];
		if (map[i]==0){
		cout << "error";
		}
	}


hmm yea it stops working
i am trying to get memory for the two pointers
map is a double pointerand a char
mapprinter is just a pointer and a char
any tips?
This is a double pointer (aka pointer-to-double):
1335
1336
double *MyDoublePointer = new double;
delete MyDoublePointer;
This is a pointer to a pointer to a char (aka pointer-to-pointer-to-char):
1337
1338
1339
1340
char **MyPointerToPointerToChar = new char*;
*MyPointerToPointerToChar = new char;
delete *MyPointerToPointerToChar;
delete MyPointerToPointerToChar;
yes but why doesn't this work?
What do you mean by "doesn't work"? Does it crash? Does it print "error"? Does it just not do what you want it to do? Does it quit its job and drink alcoholic beverages at the local bar?
prints the followin error"Unhandled exception at 0x011a2387 in pathfinding1.exe: 0xC0000005: Access violation writing location 0xcccccccc."
and points to map=0xcccccccc....
That means that map is uninitialized.
that doesn't make much sense because it is initialized even when i go over it it says char **maps::map
and would it run with out being initialized?
Last edited on
This is an uninitialized variable:

int x;


This is an initialized variable:

int x = 0;
ahh i get you...
so i need to initialize before creating space?
no way around that?
closed account (o1vk4iN6)
8008135
8008136
double myLuck = 0.0;
// what 


Sorry I had to, are these features documented anywhere L B ?
@xerzi yeah they were documented in one of the old articles on using forum code tags. The numbers can be up to 263 - 2, for reference:
9223372036854775805
9223372036854775806
//
//after this line it breaks 


@ToLesto yes, you have to initialize it to something. In your case you need to initialize it to an array of pointers and then for each pointer initialize it appropriately.
Last edited on
Topic archived. No new replies allowed.