vector<TPoint> planes[4];
-
Hi,
Was ist hier falsch?
Im header steht
vector<TPoint> planes[4];in der cpp:
for(long x=225; x<530; x=x+46){ for(long y=23; y<330; y=y+46){ TPoint p[4]; p[0].x = x; p[0].y = y; p[1].x = x+43; p[1].y = y; p[2].x = x+43; p[2].y = y+43; p[3].x = x; p[3].y = y+43; planes->push_back(*p); } }Wenn ich mit ShowMessage folgende ausgabe
z.B ShowMessage(planes[1][1].y);
gibt eine AccsessViolation ausz.B ShowMessage(planes[6][1].y);
Kein Fehler gibt aber 49332 ausMerkwürdigerweise kann ich auch
ShowMessage(planes[7][7].y); ausgaben
Kein Fehler gibt aber 272135028 ausVerstehe ich nicht. Der Vector sollte doch 49 groß sein
4 TPoints jeweils
-
Was du da oben deklariert hast ist ein statisches Array mit 4 Elementen vom Typ vector<TPoint>. Du wolltest bestimmt einen vector auf ein statisches Array von TPoint mit 4 Elementen.
-
Wo müsste in diesem Fall die 4 hin?
-
Das müßte dann eher so aussehen: vector<TPoint[4]>
Wobei so etwas wahrscheinlich garnicht funktioniert. Ich würde auch keine statischen Arrays in einen vector packen. Enweder dynamische Array (wenn sie sehr groß werden) oder in deinem Fall lieber eine struct, die 4 mal TPoint enthält.
-
Das mit der struct habe ich auch schon gemacht. Bleibe jetzt auch dabei.
Im header
typedef struct TagPlanes { TPoint a,b,c,d; }TPlanes; vector<TPlanes> planes;cpp
for(long x=225; x<530; x=x+46){ for(long y=23; y<330; y=y+46){ TPlanes p; p.a.x = x; p.a.y = y; p.b.x = x+43; p.b.y = y; p.c.x = x+43; p.c.y = y+43; p.d.x = x; p.d.y = y+43; planes.push_back(p); } }Dank für die Antworten
-
Bloß als Hinweis. Das hier:
typedef struct TagPlanes { TPoint a,b,c,d; }TPlanes;ist C-typisch. In C++ macht man das eher so:
struct TPlanes { TPoint a,b,c,d; };