Archived

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

Copying an array reference

This topic is 5316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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
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
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