Archived

This topic is now archived and is closed to further replies.

origil

A compiler gone bad....

Recommended Posts

So I''ll simply begin with this concept:
It''s not my mistake, it''s my compiler which doesn''t accept it... and such a perfectionist snob he is... So I would like some people to help me with overcoming my problem, not talking about my temporary insanity, talking about why my compiler doesn''t like me having a pointer to a 2D array. Ok, now seriously, don''t want to waste your time. [Too late though].
char * *p = new char[20][30];
I realize the ''p'' should be declared differently than as I have declared above, but how?
I didn''t really get the concept of pointers to 2 dimensional arrays.
Any help would be appreciated.

Share this post


Link to post
Share on other sites
Actually it is your mistake.

Your compiler expected something like this
  
char **p;
p = new char*[width];
for(int i=0;i<width;i++)
p[i] = new char[height];


But you gave him something else. Declaring a 2d array like you did is ok for static arrays, but doesn''t work for dynamic arrays.

If you look at the code I gave, the first new creates an array of char pointers, then for each pointer it creates an array of chars.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks a lot.
I still think my compiler should do what I mean and not what I type but that''s the problem with compilers today

Share this post


Link to post
Share on other sites