Hi, all
I'm running into a problem that I've never seen before, and hope someone here can help.
I have a square grid of circles connected by lines:
o--o--o--o--o | | | | | o--o--o--o--o | | | | | o--o--o--o--o
The circles have different attributes; so do the lines. The basic data type I'm using is an array of pointers; each pointer points to a record of information about its circle. So far, so good.
Each circle's record includes an array of pointers that point to the record of the (up to) 4 lines emanating from that circle. Likewise, I want each line record to be able to point to its two circles. This way they are cross-referential: when I'm working with a line I want to be able to find the circles it connects to, and when I'm working with a circle I want to be able to identify its (up to) 4 lines.
So the code says: --------------------- type PCircle = ^CircleRec; CircleRec = record radius : double; x, y : double; t : array[0..3] of Pline; <-- "unknown identifier 'Pline'" end;
Pline = ^LineRec; LineRec = record node_end : PCircle; width, length, end;
Pnodary = ^nodary; nodary(wx, wy : shortCard) = array[1..wx,1..wy] of PCircle; -------------------
Naturally the compiler complains about the unknown identifier "Pline". And of course, if I reverse the order of the two records, it then complains about the unknown identifier PCircle.
Is there any way to "forward declare" a record? Or am I going to have to do a serious reworking of how I handle the data?
I realize of course that I could just say, I just left circle [x,y] going left, so the circle at the end of this line should be circle [x+1,y]. This utterly simple method is unfortunately not open to me, due to what data my program has access to and what it's not allowed to see.
many thanks, Toby
Toby Ewing wrote:
type PCircle = ^CircleRec; CircleRec = record radius : double; x, y : double; t : array[0..3] of Pline; <-- "unknown identifier 'Pline'" end;
Pline = ^LineRec; LineRec = record node_end : PCircle; width, length, end;
This is a well known problem. The solution is to move the PLine pointer type definition upward, which is allowed as long as it stays within the same type declaration part. Note, that in your example the Pline type definition is already above the LineRec type definition that it references.
Pline = ^LineRec; PCircle = ^CircleRec; CircleRec = record radius : double; x, y : double; t : array[0..3] of Pline; end; LineRec = record node_end : PCircle; width, length : double end;
Regards,
Adriaan van Os
Hi, all, and especially Adriaan
thanks for the help. This solved it exactly.
Toby
Adriaan van Os wrote:
Toby Ewing wrote:
type PCircle = ^CircleRec; CircleRec = record radius : double; x, y : double; t : array[0..3] of Pline; <-- "unknown identifier 'Pline'" end;
Pline = ^LineRec; LineRec = record node_end : PCircle; width, length : double; end;
This is a well known problem. The solution is to move the PLine pointer type definition upward, which is allowed as long as it stays within the same type declaration part. Note, that in your example the Pline type definition is already above the LineRec type definition that it references.
Pline = ^LineRec; PCircle = ^CircleRec; CircleRec = record radius : double; x, y : double; t : array[0..3] of Pline; end; LineRec = record node_end : PCircle; width, length : double end;
Regards,
Adriaan van Os