creating simple array... how to?

  • Thread starter Thread starter buu
  • Start date Start date
B

buu

I'm trying to create a simple 2-dim array of integers, but don't know how to
do that...

in definition of class, I wrote:
int *results;

while in constructor:

results = new int[256][256];


but, I got an error: C2440: '=' cannot convert from int{*}[256] to 'int *'.


what is wrong?
 
buu said:
I'm trying to create a simple 2-dim array of integers, but don't know how
to do that...

in definition of class, I wrote:
int *results;

while in constructor:

results = new int[256][256];


but, I got an error: C2440: '=' cannot convert from int{*}[256] to 'int
*'.


what is wrong?

Try this instead:

I'm assuming C++, as you don't specify.

int x[][] = new int[256][256];

The reason your attempt does not work is because a pointer to int is not the
same as an array name, although the array name (once the array is properly
declared) can be used as a pseudo-pointer to the array.
 
PvdG42 said:
buu said:
I'm trying to create a simple 2-dim array of integers, but don't know how
to do that...

in definition of class, I wrote:
int *results;

while in constructor:

results = new int[256][256];


but, I got an error: C2440: '=' cannot convert from int{*}[256] to 'int
*'.


what is wrong?

Try this instead:

I'm assuming C++, as you don't specify.

int x[][] = new int[256][256];

The reason your attempt does not work is because a pointer to int is not
the same as an array name, although the array name (once the array is
properly declared) can be used as a pseudo-pointer to the array.

yes, it's c++

for the statement:
int x[][] = new int[256][256];

I got an error:
error C2440: '=' : cannot convert from 'int (*)[256] to 'int'
 
buu said:
PvdG42 said:
buu said:
I'm trying to create a simple 2-dim array of integers, but don't know
how to do that...

in definition of class, I wrote:
int *results;

while in constructor:

results = new int[256][256];


but, I got an error: C2440: '=' cannot convert from int{*}[256] to 'int
*'.


what is wrong?

Try this instead:

I'm assuming C++, as you don't specify.

int x[][] = new int[256][256];

The reason your attempt does not work is because a pointer to int is not
the same as an array name, although the array name (once the array is
properly declared) can be used as a pseudo-pointer to the array.

yes, it's c++

for the statement:
int x[][] = new int[256][256];

I got an error:
error C2440: '=' : cannot convert from 'int (*)[256] to 'int'

As Peter says, I gave you standard C++, as you didn't indicate otherwise.
 
Back
Top