Topic: Pointer to Multidimensional Array
Author: mikew@csn.net (Michael Woinoski)
Date: 1995/04/19 Raw View
Josh Fallon (FallonJB95%cs29@cadetmail.usafa.af.mil) wrote:
: Hi,
: I am relativly new to C++ and am having a small problem. I want to
: create a pointer to a multidimensional array, but the compiler says that it
: can't convert one type to another. Here is the troublesome line
: Unsigned Int* MyName = New Char[8000][3] ;
: If I make it one dimensional, it works fine, but otherwise I get the "Can't
: convert Char[3] to Unsigned Int*. I realize I am probably violating some
: basic rule, so if anyone can help me out, I'd appreciate it. Thanks.
: E-mail or posting is fine.
See the FAQ for comp.lang.c. In the mean time, try this:
char (*MyName)[3] = new char[8000][3];
Remember that C and C++ don't really have 2-D arrays; they only have 1-D
arrays, but an array can have items that are themselves arrays. So...
char table[10][80];
defines an array of 10 items; each item is an array of 80 char. To assign
table's address to a pointer, that pointer has to point to "an array of 80
char", and because of C++ precendence rules, you need the parens in the
pointer definition:
char (*tp)[80] = table;
BTW: howcome the base type for your pointer was "unsigned int", but
you used "new char..."?
Hope this helps,
--
Mike Woinoski
Author: FallonJB95%cs29@cadetmail.usafa.af.mil (Josh Fallon)
Date: 1995/04/18 Raw View
Hi,
I am relativly new to C++ and am having a small problem. I want to
create a pointer to a multidimensional array, but the compiler says that it
can't convert one type to another. Here is the troublesome line
Unsigned Int* MyName = New Char[8000][3] ;
If I make it one dimensional, it works fine, but otherwise I get the "Can't
convert Char[3] to Unsigned Int*. I realize I am probably violating some
basic rule, so if anyone can help me out, I'd appreciate it. Thanks.
E-mail or posting is fine.
--Josh
Fallonjb95%cs29@cadetmail.usafa.af.mil