struct triangle {
triangle( vertice * p0, vertice * p1, vertice * p2)
:tv1(0)
,tv2(0)
,tv3(0)
{
m_Vertices[0] = p0;
m_Vertices[1] = p1;
m_Vertices[2] = p2;
//SetCircumCircle();
}; triangle *tv1,*tv2,*tv3;}
struct vertice
{
vertice ( int init_val=0) :id (init_val) {};
vertice (double xx, double yy=0):x(xx),y(yy) { };
int id;
double x,y;
};
std:: vector <triangle> triangles;
void cre_triangle()
{
triangle r(0,1,2);
triangle r2(3,4,6);
r.tv1= &r2;
r.tv2=0;
r.tv3=0;
cout << r.tv1->m_Vertices[0]->id << r.tv1->m_Vertices[1]->id
<< r.tv1->m_Vertices[2]->id; //the result is 3 4 6
triangles.pushback(r);
}
int main ()
{
cre_triangle();
cout << triangles[0].tv1->m_Vertices[0]->id <<triangles[0].tv1->m_Vertices[1]->id
<<triangles[0].tv1->m_Vertices[2]->id << endl ;
// problem here (....exe has stopped working)
return 0;
}
我去了访问id和三角形r2的顶点坐标r(tv1是邻居1)并修改它 但我有一个问题(appilcation.exe已停止工作) 请你能帮帮我..
答案 0 :(得分:0)
您正在存储指向本地变量的指针。 cre_triangle()
完成后,这些变量会瓦解。使用共享指针或只是按副本存储。