The v2 vector contains ponters to float values in the array v.
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main (int argc, char *argv[])
- { float a = 3, b = 2, c = 1;
- float v[3];
- v[0] = a; v[1] = b; v[2] = c;
- vector<float*> v2(3);
- // v2[0] = v+0; v2[1] = v+1; v2[2] = v+2; // runs fine, but
- v2[0] = v+0; v2[1] = v+1; v2.push_back(v+2); // ****ERROR****
- cout << *(v2[0]) << " " << *v2[1] << " " << *v2[2] << endl;
- return 0;
- }
if I comment the push_back line the commented line runs fine.
Can't I use put_back in this way? I cannot see the mistake by myself, so I would apriciate very much any hints that would explain the error.
purso