What's wrong with my code?

I don't really see the thing I am doing wrong.
Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void Test::AssignToRods(double a,double b,double c) {
    
    GetPosition(a,b,c);
    AssignRodArrays();

    // 3 is position in array
    for (int i = 0; i < 3; i++) {
        
        Rods[e21[3]].push_back(e21[i]);
        std::cout <<  e21[i] << std::endl;
        std::cout <<  Rods[e21[3]].at(e21[i]) << std::endl;
        std::cout <<  " " << std::endl;
    }
}


The output is

1
2
3
4
5
6
7
8
0.919392
0.919392
 
1.60537
0.919392
 
0
0.919392
Rods[e21[3]].at(e21[i])

You printed e21[i], which was a decimal. How could you do an at() of a decimal?

Try: Rods[e21[3]].at(i)

Edit: and I know it really doesn't matter too much, but the indices of an array/vector can never be negative. Might be better practice to make your for loop:
for (unsigned int i = 0; i < 3; i++)
Last edited on
OhoHohoOH. Stupid me. Thanks.
Topic archived. No new replies allowed.