Я бы хотел сделать следующее. но не знаю как:
//have two vectors: vector1 (full of numbers), vector2 (empty)
//with vectors, I mean STL vectors
//outer loop
{
//inner loop
{
//vector2 gets written more and more over iterations of inner loop
//elements of vector1 are needed for this
} //end of inner loop
//now data of vector1 is not needed anymore and vector2 takes the role of
//vector 1 in the next iteration of the outer loop
//old approach (costly):
//clear vector1 ,copy vector2's data to vector1, clear vector2
//wanted:
//forget about vector1's data
//somehow 'rename' vector2 as 'vector1'
//(e.g. call vector2's data 'vector1')
//do something so vector2 is empty again
//(e.g. when referring to vector2 in the next
//iteration of outer loop it should be an empty vector in the
//beginning.)
} // end of outer loop
Я пытался
vector<double> &vector1 = vector2;
vector2.clear();
но я думаю, что проблема в том, что vector1 - это ссылка на vector2, который затем удаляется.
Есть идеи?