H
Hamish
Hello, lately I've been having a lot of trouble with the std::vector. Seems
to create unpredictable behaviour within my code.
Example:
struct Switch{
int i;
int j;
double d;
};
std::vector<Switch> Switches;
Now I have a for...loop:
int h = Switches.size();
for(int i=0;i<Switches.size()-1;i++){
/*do stuff here*/
}
The problem is, when h (Switches.size()) equals 0, the for...loop is still
entered, and runs infinitely.
However, if I use the line:
for(int i=0;i<h-1;i++){
then there is not a problem.
Anyone got any ideas as to what is going on, cos this is ruining my New
Year!
to create unpredictable behaviour within my code.
Example:
struct Switch{
int i;
int j;
double d;
};
std::vector<Switch> Switches;
Now I have a for...loop:
int h = Switches.size();
for(int i=0;i<Switches.size()-1;i++){
/*do stuff here*/
}
The problem is, when h (Switches.size()) equals 0, the for...loop is still
entered, and runs infinitely.
However, if I use the line:
for(int i=0;i<h-1;i++){
then there is not a problem.
Anyone got any ideas as to what is going on, cos this is ruining my New
Year!