Skip to main content
gamedev.net
🔒 Locked

accessing array index through pointer

Started by mjs1 3 replies 300+ views
Original Post
mjs1
mjs1
My function has as a parameter a pointer to an array. I'm not sure what the proper syntax is to access an element of the array the pointer is referencing: int Region :: boundingBoxTest(S_Shape* iShape, vector<S_Face>* iFaces) { for (int i = 0; i < iFaces->size(); i++) { if (isBBoxDisjoint(iFaces) == false) // this is a syntax error { } } } Thanks for any help!
Conner McCloud
Conner McCloud
iFaces is a vector*. So, iFaces[n] refers to the n-th vector in the 'array' iFaces. In order to turn iFaces into a vector, it must be dereferenced:
(*iFaces).size();(*iFaces)[5];//etc


In addition to this, consider passing iFaces as a references, rather than a pointer. The chances of the calling function screwing up and sending boundingBoxTest bad data is considerably smaller that way. Plus, you avoid all the explicit dereferences.

CM
Last Attacker
Last Attacker
Could you give us a prototype of isBBoxDisjoint?
Just to see what parameters that accepts. Maybe its that because as far as I can remember (a few years back when I still used vectors before writing my own) a pointer to a vector, you can still access its array elements by using it asif it wasn't a pointer like you did with iFaces.
I'm speaking under correction.
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
Dave Hunt
Dave Hunt
You can also use
iFaces->at(i);

Topic Locked

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

Sign in to reply to this topic.