Skip to main content
GameDev.net gamedev.net
🔒 Locked

Copying an array reference

Started by jonbell May 26, 2003 at 2:26 PM 2 replies 250+ views
Original Post
jonbell
jonbell
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 *''
Lektrix
Lektrix
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]
jonbell
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?

[edited by - jonbell on May 26, 2003 4:02:25 PM]
BriTeg
BriTeg
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.

Brianmiserere nostri <font color=#BC

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.