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

Vector help

Started by TutenStain May 12, 2010 at 9:12 AM 3 replies 800+ views
Original Post
TutenStain
TutenStain
Probably a easy question but here it goes. Why does this always bring me to an instant crasch? Vector myX; Vector myZ; //insert data into vectors... //Crash when reading like this: float test = myX[myZ[4]];
RabidDog
RabidDog
Use .at() instead of []

float test = myX.at(myZ.at(4));

Won't stop the crash but will likely give you an out of bounds access error.
RabidDog
RabidDog
AND I just realized you're trying to index into an array with a float index. That won't work.
Evil Steve
Evil Steve
Quote:
Original post by RabidDog
AND I just realized you're trying to index into an array with a float index. That won't work.
It'll work, but it's probably a bad idea to try and do it.

As for the actual problem, either myZ doesn't have 4 elements in it, or myX doesn't have whatever myZ[4] is elements in it.
TutenStain
TutenStain
Quote:
Original post by Evil Steve
Quote:
Original post by RabidDog
AND I just realized you're trying to index into an array with a float index. That won't work.
It'll work, but it's probably a bad idea to try and do it.

As for the actual problem, either myZ doesn't have 4 elements in it, or myX doesn't have whatever myZ[4] is elements in it.


Spot on.

Apparently my for loop did not fill the vectors correctly.

Thanks a bunch.

Topic Locked

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

Sign in to reply to this topic.