double pointer help

Nov 6, 2012 at 9:53pm


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?
Nov 6, 2012 at 10:01pm
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;
Nov 6, 2012 at 10:29pm
yes but why doesn't this work?
Nov 6, 2012 at 10:30pm
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?
Nov 6, 2012 at 10:33pm
prints the followin error"Unhandled exception at 0x011a2387 in pathfinding1.exe: 0xC0000005: Access violation writing location 0xcccccccc."
and points to map=0xcccccccc....
Nov 6, 2012 at 10:42pm
That means that map is uninitialized.
Nov 6, 2012 at 10:45pm
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 Nov 6, 2012 at 10:46pm
Nov 6, 2012 at 10:48pm
This is an uninitialized variable:

int x;


This is an initialized variable:

int x = 0;
Nov 6, 2012 at 10:51pm
ahh i get you...
so i need to initialize before creating space?
no way around that?
Nov 6, 2012 at 11:02pm
closed account (o1vk4iN6)
8008135
8008136
double myLuck = 0.0;
// what 


Sorry I had to, are these features documented anywhere L B ?
Nov 6, 2012 at 11:13pm
@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 Nov 6, 2012 at 11:14pm
Topic archived. No new replies allowed.