When I run the code below, in my trainingVector I get:
{(10,0),(10,0),(10,0)...}
instead of:
{(0,0),(1,0),(2,0)...}
How do i make this work correctly?
vector< vector< double > * > trainingVector;
for(int i=0;i<10;i++){
vector<double> ok (2,0);
ok[0]=i;
trainingVector.push_back(&ok)
}
The method you are using right now won’t work because the life of each vector
okobject lasts only within the iteration before it falls out of scope and dies.You need to do this instead:
Be aware that you will need to free each inner vector manually later. Or you’ll get a memory leak.
Alternatively, you can do it without pointers all together:
Though this latter method implies copying the inner vector when it is put into the outer vector.