20,741
edits
mNo edit summary |
mNo edit summary |
||
| Line 46: | Line 46: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Now, this is fairly repetitive and not overly scalable, because the variable names are hard coded and need to be changed in a lot of places in the source code. So, it would be better to use a vector of waypoints instead. A vector is a list of things (variables) that can be easily accessed using an index into the vector. Pretty much like an array in C or C++, with the added advantage that the vector can be dynamically resized, e.g. using the setsize() library call. Consider the following example: | Now, this is fairly repetitive and not overly scalable, because the variable names are hard coded and need to be changed in a lot of places in the source code. | ||
Just imagine we'd need to support more than just 5 waypoints, like maybe 10, 20, 50 or maybe even 1000 waypoints. As you can see, this method is very inflexible, complicated, tedious and error-prone. | |||
So, it would be better to use a vector of waypoints instead. A vector is a list of things (variables) that can be easily accessed using an index into the vector. Pretty much like an array in C or C++, with the added advantage that the vector can be dynamically resized, e.g. using the setsize() library call. Consider the following example: | |||