Archived

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

jonbell

Copying an array reference

Recommended Posts

jonbell    100
Given an array of pointer to ints, how can i copy a refernce to the array? int *array[100]; int *i i = array; i[0] = blah blah; I''m sure you get what i mean but i get the following e error C2440: ''='' : cannot convert from ''int *[100]'' to ''int *''

Share this post


Link to post
Share on other sites
Lektrix    106
As an array of pointers is (basically) a pointer to a pointer:

int *array[100];

int **i = array;

...


I'm not quite sure why you are asking about a "reference", though in your example you are using pointers, though.

[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on May 26, 2003 3:50:09 PM]

Share this post


Link to post
Share on other sites
jonbell    100
If i use the above technique i can assign my new variable to the array but i cannot access it like an array :

i[5] = xxx;

is it possible to do this?

[edited by - jonbell on May 26, 2003 4:02:25 PM]

Share this post


Link to post
Share on other sites
BriTeg    168
quote:
Original post by jonbell
If i use the above technique i can assign my new variable to the array but i cannot access it like an array :

i[5] = xxx;

is it possible to do this?



array is a pointer to pointers.

i is a pointer to ints.

Thus, they are not the same type.

If you declare i like Lektrix said, they are of the same type and then you could use i like you want.

Share this post


Link to post
Share on other sites