12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
#include <iostream> using namespace std; #include <vector> class point { public: int aux; }; class Class2 { public: point* aux; Class2() { } ~Class2() { aux = NULL; delete(aux); } }; void main() { vector<point> vertex; vector<Class2> linii; point aux_vert; Class2 aux_linie; for(int i=0 ; i<10 ; i++) { aux_vert.aux = i; vertex.push_back(aux_vert); /*aux_linie.aux = &vertex[vertex.size()-1];*/ linii.push_back(aux_linie); linii.back().aux = &vertex[vertex.size()-1]; //my error!!! } cout<<"vertex:"<<endl; for(int i =0;i<vertex.size(); i++) cout<<vertex[i].aux<<endl; cout<<endl<<endl<<"linii:"<<endl; for(int i =0;i<linii.size(); i++) cout<<linii[i].aux->aux<<endl; system("pause"); }
123456789101112131415161718192021222324
vertex: 0 1 2 3 4 5 6 7 8 9 linii: 0 5787436 2 -842150451 4 5 1472668336 1053 16 9
&vertex[vertex.size()-1]