Change Displayed Text SizeGrow Displayed Text SizeShrink Displayed Text Size

Wednesday, April 07, 2004

Struct vs. Class: Class wins?

I have a simple data structure for storing geospatial information, just 4 numbers. Latitude, longitude, altitude, and time. Simple, right? It would be way, way overkill to use an full on class to do this, so I implemented a nice little C struct to do it:
typedef struct _TrackPoint {
double latitude; /* Latitude */
double longitude; /* Longitude */
double altitude; /* Altitude */
double time; /* Time */
} TrackPoint;
typedef TrackPoint *TrackPointPointer;
typedef TrackPoint *TrackPointArray;

Of course, it's objective-c I'm using this data structure with. Apple does this all the time, treating structs like NSPoint and NSRect as if they were objects, when they are not. While I have tried to follow the example of Apple and GNUStep in implementing my simple data structure, Xcode isn't allowing me to treat it like it does NSRect.
This is annoying the hell out of me. Now I'm going to have to make an object like the above structure, of which I expect to have arrays of hundreds or thousands... that's not cool.

Why can't I just do it as Apple and GNUStep do? I've searched for other examples of structs posing as classes/objects, but no luck.
Sure, as soon as I post this I find the answer on [CocoaDev], which I had already searched a number of times!

4/07/2004 06:54:00 PM ] [  0 comments  ]
A good quick laugh