好的,我正在努力解决指针问题,但是一旦我开始使用类似class **c
我迷路的东西。
说我有
struct POINT{ int x, y, z; };
struct POLYGON{ POINT **vertices; int size; };
POINT points[10];
InputPoints(points,10); //fills up the points array somehow
POLYGON square;
//the following is where I'm lost
square.vertices = new *POINT[4];
square.vertices[0] = *points[2];
square.vertices[1] = *points[4];
square.vertices[2] = *points[1];
square.vertices[3] = *points[7];
此时,square
应该保存一个指针数组,每个指针引用points
. 然后
square.vertices[2].x = 200; //I think this is done wrong too
应更改points[1].x
为 200。
我将如何更改上述代码以实际执行此操作?虽然我知道使用 std::vector 会更好,但我正在尝试了解指针的工作原理。